[Tutor] put?

Marc Tompkins marc.tompkins at gmail.com
Thu May 1 20:59:03 CEST 2008


On Thu, May 1, 2008 at 12:51 AM, Ross Glover <ross at ross.mayfirst.org> wrote:

> put, get=os.popen4("dict -d wn " + (word))
>
> Something that can be a little confusing at first (and I haven't seen
anybody mention it yet, so I thought I'd chime in) is that you can assign
multiple variables at the same time.  It can be a little jarring if you
aren't used to it.  So far you've probably only run into single
assignments:  x=5, dog=cat, etc.
In contrast, this line runs a command that returns two values, and assigns
those values to two variables called "put" and "get".
If you weren't aware that multiple assignments were possible (and that this
is what they look like), then this is a very confusing line of code indeed.

<rant>
Also - no offense to whoever put up the code you're learning from, but those
variable names were poorly chosen!  Since you're just starting out, you have
the opportunity to learn good habits early.  Don't use verbs as variable
names!  It is almost guaranteed to confuse the heck out of anybody who has
to read your code later - maybe even yourself, if you don't look at it
often.
Variable naming conventions are a very contentious topic - you'll get
fanatical supporters of "x" and "y", or Hungarian notation, or
"VeryDescriptiveVariableName", or whatever, and I'm not going to make an
endorsement... but I would make two hard and fast rules:
-  Don't use variable names that conflict with reserved words, e.g. don't
create a list variable and name it "list".
-  Don't use variable names that SOUND like they might conflict with
reserved words - like "put" and "get".

</rant>

-- 
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080501/df6d42c2/attachment.htm>


More information about the Tutor mailing list