What are you expecting to do with those variables and values later?
--
Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
Well, you start by reading a book on how to program. You would
then learn that what you want (in all likelihood) is a
dictionary/map structure for dynamically created key/value pairs.
Once you have progressed from your current apprenticeship and
achieved the rank of third-degree journeyman programmer, the ways
of dynamic variable creation will avail themselves.
> i = 0
> nameNos = []
> nos = []
> for option in ourOptions():
> nameNos.append('optionNo%d' % i)
> nos.append(i)
> i += 1
>
> The idea is that through every iteration of option, I can create a new
> variable such as 'optionNo0', 'optionNo1' etc and assign values such as '0',
> '1' etc to them. Of course that code doesn't work. What would?
As stated above, you want a dictionary where your keys are
'optionNo%d' % i
and your values are "i". You can also use the more idiomatic
for i, option in enumerate(ourOptions()):
...
and skip the manual initialization and incrementation of "i". Or
even more succinctly, you could pass the above as a generator to
the dict() initialization. But that's a level-2 apprentice bit
of code. Patience grasshopper.
And as additional weirdness, you don't actually make use of
"option" in your for-loop...
-tkc
The aim was not arrogance, but expression of exasperation at your
"using c.l.p to write my code and interpret my error messages"
programming style that seems to indicate that you don't
understand how to use tools like your editor, traceback messages,
& google; or that you've not invested the time to learn
programming concepts such as when to use dictionaries/maps, HTML,
HTTP/server stuff, SMTP/email stuff, or research hosting provider
information.
Let's take a tour back through some of your previous posts to the
list to see why the exasperation:
Just in my readily-available offline archives, I count at least 4
off-topic (non-Python) posts, three of which you KNEW were OT
because you put "OT" in the subject[1]. The 4th[2] is just a
google-search away. Any basic HTML tutorial on using form
elements would show you how to do this. And on the topic of
googling for answers you had questions about good mailers[3], a
quick search for "python send mail" turns up a multitude of
built-in and code-copyable solutions.
You don't seem to learn from previous answers[4] where the
solution in the first response was "make sure you're not masking
the built-in module with a same-named file in your project
directory", only to have the same issue in the 2nd email. While
it's somewhat forgivable as I too have accidentally masked my
ability to send email by having an "email" module in the local
directory, I learned to google the traceback's core message
"ImportError: No module named base64MIME" which gave me the answer.
You don't seem to read tracebacks[5]. When you do get tracebacks
that you don't understand, many of your initial posts either post
them in some funky line-numbered format[6] that makes them hard
to read (though can be helpful, so this isn't as grievous)), or
you simply omit the traceback completely[7]. Even if asked
explicitly for them[8]. They contain valuable information. Your
omission of them frustrates anybody trying to help. There's the
omission of key information[9] or improperly hand-transcribing
code instead of copy-and-pasting the actual code.
And that doesn't even touch on the issues of repeated top-posting
which is just annoying. Folks have been pretty lax, giving you
subtle "changed to inline format to make it easier to follow",
but you don't seem to pick up on the suggestion. I'll make it
explicit: post replies inline for best results.
You'll find that comp.lang.python is a generally friendly place,
but HELP US HELP YOU. Try doing your own research first, reading
error messages, giving us the tools we need to help you, and
adhering to conventions like inline posting.
I'm glad if my underlying suggestion of using a dict helped you
reach a solution, but would be far more glad if you'd take this
message to heart -- not as an enumeration transgressions, but as
a way you can better ingratiate yourself with the list.
-tkc
[1]
OT Virtual Server Host
(OT) Recommend FTP Client
(OT) Where Are Cookies Stored
[2] Workaround to Add values to TextArea
[3] A Good Mailer
[4]
Can't Find Module
Python Will Not Send Email!!
[5] Switching Databases
[6] Problem w/ smtplib
[7]
Calendar Problem
Calendar Stuff
...and others
[8] Switching Databases
[9]
Nested Dicts
Calendar Stuff
I haven't been around the list much lately, so I don't know if your
earlier posts were ever preceded by "please help a struggling
right-brain artist", but on this group it certainly wouldn't have hurt.
> Thank you for your help anyway. Thank you for your patience. Please try
> to understand. It starts by understanding you can't understand. You have
> my continued promise that I will do all I can to edit my questions as
> intelligently as you would before I post them. Trust me, I don't like
> looking foolish, and I know I do. You should recognize that that alone
> is chiding enough. It doesn't stop me, however, for continuing to
> program. The whole universe is a program. I program to understand it in
> a way you couldn't even begin to grasp.
>
Well, if we were looking for arrogance we could easily interpret that
last statement as such. Please remember that although we are mainly
left-brain types on this list some of us do have artistic and musical
skills. Some people will therefore probably be closer to your conception
than you anticipate (though I confess I am unlikely to be one of them).
> BTW, although I know full well about dictionaries, I didn't know one
> could use them like you indicated, nor would I have known how to google
> it. I did try googling, FYI.
> V
>
The PSF has recently started to take diversity more seriously, and this
should ideally include cultural diversity in all sorts of dimensions, so
I hope you will stick around long enough to inject the artistic approach
from time to time. Python has a *very* diverse user list, but not all
are equally represented in the on-line communities.
Tim is correct, the Python list is a pretty friendly place as far as
netiquette standards go, and I am happy this thread didn't just turn
into ugly name calling (which it could have with a less adult approach
by the participants).
regards
Steve
--
Steve Holden Chairman, Python Software Foundation
The Python Community Conference http://python.org/psf/
PyCon 2010 Atlanta Feb 19-21 http://us.pycon.org/
Watch PyCon on video now! http://pycon.blip.tv/
I'm not aware that the python-list is subject to that kind of
censorship. I don't see why you can't subscribe under any name you want,
and I'm certainly not aware of any banning mechanism.
However, you over-estimate the powers of the PSF chairman if you think I
have anything to do with who gets to use the mailing list and who
doesn't ...
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/
I'm not sure how I become the one accused of arrogance. Or where
my right-brain ceases to be as magnificent as yours and my
capacity to understand you falls so short -- whether it's
speaking Spanish or being conversational in ASL; authoring and
illustrating a children's book; striving for beautiful code
(Stephen's recent post well summarizes elegance in code);
submitting my work status reports in [limerick, sonnet, rap,
comic, pop-music spoof, crossword puzzle, etc]; cooking;
sewing/crafting/needlework; painting; wood-working;
guitar-playing; the philosophy minor; creating balloon art, etc.
It would seem I use both sides of the brain, like many others
on the list here. For just a single example reference, check out
Adrian Holovaty (one of the Django founders) jamming some
beautiful guitar-work on YouTube.
> The problem is that I quite literally can't think like you. I
> have to force myself to do it every time. To you it's as
> natural as breathing, which is why you can't relate.
In time and with repeated exercise, it's possible to develop both
sides of the brain. One side may dominate (and I'll forthrightly
declare that my left brain dominates), but it doesn't excuse
failure to strengthen the weaker side.
> You have my continued promise that I will do all
> I can to edit my questions as intelligently as you would
> before I post them. Trust me, I don't like looking foolish,
> and I know I do. You should recognize that that alone is
> chiding enough. It doesn't stop me, however, for continuing to
> program.
I appreciate your efforts to edit -- I've provided a bit of a
check-list that you can use to make sure you've googled for the
obvious; taken the time understand the problem in both a local
context and stepping away to see the big-picture view of the
problem; taken a survey of your available tools; read the
tracebacks to try and understand what they're telling you; and
when you post (with replies inline), provide the code exactly as
it's erroring for you (stripped down examples are nice, as long
as they reproduce the problem) instead of transcribing something
like your code; if you get exceptions post the full traceback not
just your interpretation of them; and if you're running in a
non-conventional environment such as a web-server instead of a
standalone application, it's helpful to note it up front. The
perennial "Smart Questions" article by ESR might also be a useful
read in ingratiating yourself.
By demonstrating that you've exerted the effort to help the list
help you, it encourages us to provide the best answers. On the
whole, the list does enjoy being helpful.
And when you do get a helpful answer, saying thanks is always
appreciated...
> I appreciate Tim's advice
something I've noted you've improved on lately...thanks in return.
> I came across as I intended.
Your intent was to come across condescendingly as a right-brained
artist struggling to be understood yet obdurately plunging ahead
without striving to facilitate others in helping you?
-tkc