Re: [Tutor] How to perform variable assignment and

2009-10-03 Thread Steve Willoughby
Oxymoron wrote: > While having an assignment as an expression could be convenient in > places (I have had my moments where I wish it was!), that particular > usage is also a source of common bugs. Often in conditional statements Me, too. I grumble every time I have to take two separate statements

Re: [Tutor] How to perform variable assignment and

2009-10-03 Thread Mark Tolonen
"wesley chun" wrote in message [snip] ... however, there is a tiny bug: if the $HOME environment variable is *not* set, you will get a KeyError exception. one solution is to add a default value to your get() method call so that it returns an object with a Boolean False value: No KeyError. D

Re: [Tutor] How to perform variable assignment and

2009-10-03 Thread Oxymoron
(Did not reply to list earlier, apologies) On Sat, Oct 3, 2009 at 7:47 PM, Didar Hossain wrote: > >>> There are probably various syntactic tricks to achieve the same, > however, > >>> the main reason you can't do it is that assignment in Python is a > statement > >>> rather than an expression, i.

Re: [Tutor] How to perform variable assignment and

2009-10-03 Thread Didar Hossain
On Sat, Oct 3, 2009 at 1:34 PM, Rich Lovely wrote: > 2009/10/3 wesley chun : >> On Fri, Oct 2, 2009 at 11:14 PM, Oxymoron wrote: >>> Hello, >>> >>> On Sat, Oct 3, 2009 at 3:56 PM, Didar Hossain >>> wrote: homedir = os.environ.get('HOME') if homedir:    print "My home dir

Re: [Tutor] How to perform variable assignment and

2009-10-03 Thread Rich Lovely
2009/10/3 wesley chun : > On Fri, Oct 2, 2009 at 11:14 PM, Oxymoron wrote: >> Hello, >> >> On Sat, Oct 3, 2009 at 3:56 PM, Didar Hossain >> wrote: >>> >>> homedir = os.environ.get('HOME') >>> >>> if homedir: >>>    print "My home directory is %s" % homedir >>> >>> >>> I do this in Perl - >>> >>>

Re: [Tutor] How to perform variable assignment and

2009-10-02 Thread wesley chun
On Fri, Oct 2, 2009 at 11:14 PM, Oxymoron wrote: > Hello, > > On Sat, Oct 3, 2009 at 3:56 PM, Didar Hossain > wrote: >> >> homedir = os.environ.get('HOME') >> >> if homedir: >>    print "My home directory is %s" % homedir >> >> >> I do this in Perl - >> >> my $home; >> >> if ($home = $ENV{'HOME'}

Re: [Tutor] How to perform variable assignment and

2009-10-02 Thread Oxymoron
Hello, On Sat, Oct 3, 2009 at 3:56 PM, Didar Hossain wrote: > homedir = os.environ.get('HOME') > > if homedir: >print "My home directory is %s" % homedir > > > I do this in Perl - > > my $home; > > if ($home = $ENV{'HOME'}) { print "My home directory is $home\n"; } > > Can I do a similar shor

[Tutor] How to perform variable assignment and

2009-10-02 Thread Didar Hossain
Hi, I am currently learning Python and I was wondering is there a shorter way to do the following - import os homedir = os.environ.get('HOME') if homedir: print "My home directory is %s" % homedir I do this in Perl - my $home; if ($home = $ENV{'HOME'}) { print "My home directory is $hom