[Fwd: Re: [Tutor] Trying to find a value in a function.]

Gregor Lingl glingl@aon.at
Mon Mar 10 12:50:02 2003


D2 schrieb:

> I'm trying to find a value in a fonction given the name of the function
> and the name of the variable.
> The variable is not an attribute nor an argument.
>
> Here is the function
>
> ---------
> def some_func(self):
>     props=['a', 'b', 'c']
> ---------
>
> I tried to use some_func.func_code.co_varnames but it only returned the
> tuple below.
>
> ---------
> ('self', '_props')
> ---------

Hi D2!

I suggest that you be more careful in youre questions (and
possibly in your programs)
Apparently you use props and _props for the same thing (a
variable name)?

Your some_func.func_code.co_varnames is heavy stuff, which is
rarely necessary to use. I wonder what you want to accomplish.

Your function is a rather strange and useless thing. It does nothing
and it returns nothing (namely None). Did you invent it only to serve
as an example? For what?

As props in your example is a local name, the variable (i. e. name
+ reference to an object) only exists during runtime of the function.
So I think. it makes no sense to ask for the value of props except
after the assignment to it (in the function body) and before the
execution of some_func is done. So you had to insert an appropriate
statement in the function body ?!?

For me it's hard to give an appropriate answer, because I can't
figure out for what purpose you need it.

What sources (books, tutorials, examples) do you use when
working with Python?

Please excuse, if my statement is totally irrelevant for you

Regards, Gregor



>
> How can i get the value of the _props variable ?
>
> TIA
>
>
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>