newbie question

Jasonbail jasonbail at aol.com
Sun May 27 19:31:01 EDT 2001


>> I'm fairly new to programming,
>
>> My questions is, is there anyway to create a reference to a pre-existing
>> variable by using variables?
>
>> for example if I have a variable daily_count
>
>> can I access that variable by using "daily_" and "count" thats stored in
>other
>> variables?
>
>Since you are new to programming, I think the best answer here would
>be to ask you some more questions. The most important one in these cases
>is always: 
>
>  Why would you want to do that?

Well let me first say that I have a tendency to leap first and then try to
figure out if I will be able to land safely.

    The idea behind my post was that I was in the process of creating a simple
app when I noticed that the majority of the code I was using to create the gui
was nearly identical. It stood to reason then that I could I define a function
that I could then use to configure the widget and that all I had to do was pass
along the name of the widget that would need configuring. And to do that I
would need to store the name in a variable to pass along to the function, which
it would then configure and at a later point I could re-configure to my hearts
content.

    Of course I don't need to do that. It took me almost the entire night to
wrap my head around the thought that I could create a method and that by
creating an instant of the method I would then be able to do what I originally
planned on doing. (sorry if I butcher the terminology here, I'm still working
on that) Some of this is very confusing at first.

   The reason why I didn't go to far in to explaining what I was doing is that
because I knew I was new to this, I knew that there was probably a better way,
but that wasn't what I was looking for. Sometimes people will try answering my
problem rather then my question. Which I dislike because regardless of my
intent I still want to know the answer to my question (which in this case
several people, I'm happy to say, have answered.)

>In Python, variables (attributes, etc, in python terminology, names) are
>always references to *objects*. The only way you can approach objects is
>to go through these names in some fashion. The objects contain the data
>and define the behavior, however. The names may refer to one object now,
>and another in the future. Multiple names can refer to the same object.
>This distinction between names and the objects they refer to is very
>important in Python, so you make sure you clearly understand this. It
>is not extremely difficult to understand and to deal with once you
>understand, but it is a common problem for many that are new to Python.
>

 I didn't quite see that until you pointed it out. After reading your post I do
see your point and I think I was probably to reserved here. I will try to be a
little bit more verbose on my questions in the future. Thanks for the feedback,
and I will take you up on the clarification as soon as I understand enough to
form a coherent question. :)

Jason



More information about the Python-list mailing list