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
"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
(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.
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
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 -
>>>
>>>
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'}
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
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