[Tutor] put?
bob gailer
bgailer at gmail.com
Fri May 2 01:02:03 CEST 2008
Marc Tompkins wrote:
> On Thu, May 1, 2008 at 12:51 AM, Ross Glover <ross at ross.mayfirst.org
> <mailto: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
No No. Python does not have "commands" and can't therefore "run" them.
A better way to express that is: on the right of the = is an expression
which Python evaluates.
> , 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 <http://www.fsrtechnologies.com>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
--
Bob Gailer
919-636-4239 Chapel Hill, NC
More information about the Tutor
mailing list