[Fwd: Re: [Tutor] Trying to find a value in a function.]
D2
borelan@wanadoo.fr
Tue Mar 11 02:47:01 2003
Hi Gregor,
Gregor Lingl a écrit:
>
> 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)?
about props, it's just a typo.
>
> 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?
>
This function is really useless and strange :) it's just to show i
wanted to get something from -inside- the function. but you answered below.
I wanted to know if it was possible to extract information from
functions as it is possible from classes.
I think you noticed that i am new to python.
> 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.
>
The case :
In an attempt to write a small application in Python, i want to allow
different users to import data from their closed legacy systems in an
object database.
The only way they can do that is by using text files.
The applications don't work the same way and don't export the data in
the same format but always in txt.
The users can't change the export format.
(the story begins before neanderthal :)
I want to automatize the process of creating objects by reading the text
files.
My first thought is to proceed as below.
1) Given the class name and constructor, describe the class's required
arguments, arguments with default values.
2) Display a form where the user can describe the structure of his text
file (field separator or length of the fields, etc.), and associate his
text files fields with the argument of the class' constructor.(for
example the 1st argument of the constructor correspond to the third
field of the text, etc.)
3) Read the text file, apply the description, and create an object for
each line by using constructor_function(*args, **keywords), the class
being an argument of the constructor.
But, the class and the constructor are not explicitely described so i
have to get the information from the source that the reason why i use
co_varnames, func_defaults, argcount, and so on.
In the state of my knowledge, i didn't find a way to display separately
the required arguments and the arguments with default values so i'm
using workarounds. By comparing the length of the arguments list to the
length of the default values list, i'll be able to determine how many
postional arguments are mandatory and then find their names in the list.
I'll be able to display a correct description of the constructor and to
call it with the correct *args list and **keywords dictionary.
There may be a better solution but that's my first attempt.
> What sources (books, tutorials, examples) do you use when
> working with Python?
>
I'm searching in Python's documentation (library reference, reference,
tutorial), tutorials on the web and so on.
> Please excuse, if my statement is totally irrelevant for you
>
Don't worry, i just want to learn and there's always something in an
answer even if the question is .... let's say, a newbie's one :)
Andre
> 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
>>
>>
>
>
>
>
>
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>