[Tutor] use the data None

Tehn Yit Chin tehn.yit.chin at gmail.com
Mon Jun 4 12:14:01 CEST 2012


Thanks for the quick answers.

The potential for the variable not to exists is when I am using the
optparser module, and I want to check if a particular parameter was passed
in or not. If the parameter was not passed in, then the variable would not
exists. Eg

If I call a python script is expecting a parameter "param1" but I failed to
passed it via the command line, I would do the following check

(options, args)=parser.parse_args()
if options.param1 != None:
         param1 = int(options.param1 )
else:
         param1 = 30

By the way, please excuse the way I am coding, I come from a C background.

I think I shall try the catch method.

Thanks!

On Mon, Jun 4, 2012 at 3:09 AM, Alan Gauld <alan.gauld at btinternet.com>wrote:

> On 04/06/12 01:39, Alan Gauld wrote:
>
>  for var in (a,b,c):
>>    if not var:
>>           print var.__name__, ' is empty or false'
>>
>
> Oops, that won't work. __name__ is not an attribute
> of object, which I thought it was...
>
> But hopefully the intention was clear.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> ______________________________**_________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>



-- 
Tehn Yit Chin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120604/d3f5d939/attachment.html>


More information about the Tutor mailing list