By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,768 Members | 2,054 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,768 IT Pros & Developers. It's quick & easy.

query regarding python script

P: n/a

Hi,

I have the following statement in one my python script :-

assert not opt_initialize or os.path.exists(initdir), "initialize implies init directory"

Could u tell please what it is intended to do?

Regards,
Shubhra Gupta


Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Shubhra Gupta wrote:
I have the following statement in one my python script :-

assert not opt_initialize or os.path.exists(initdir), "initialize implies init directory"

Could u tell please what it is intended to do?


Nobody but the author could say what it was *intended* to
do.

What it is actually doing, however, is terminating the program
if the opt_initialize flag is False or, in the case where it's
True, if there is a directory or file (!) with the path in 'initdir'.
If it does terminate the script, it will also show the string that
follows.

The lines shown will also not execute at all if the script is
run with the -O or -OO options.

Looks like it was not entirely well thought out...

-Peter
Jul 18 '05 #2

P: n/a
"Shubhra Gupta" <Sh***********@infosys.com> wrote in message
news:ma*************************************@pytho n.org...
I have the following statement in one my python script :-

assert not opt_initialize or os.path.exists(initdir), "initialize implies init directory"
Could u tell please what it is intended to do?

Regards,
Shubhra Gupta


See http://www.python.org/doc/current/ref/assert.html
--
I don't actually read my hotmail account, but you can replace hotmail with
excite if you really want to reach me.

Jul 18 '05 #3

P: n/a
Shubhra Gupta wrote:

Hi,

I have the following statement in one my python script :-

assert not opt_initialize or os.path.exists(initdir), "initialize implies
init directory"


As the or-operator is non-strict, the right side of it gets only evaluated
if the left is False. So the comment pretty much says it: If opt_initialize
is True, the not negates it and then the os.path.exists(initdir) is
executed - but orly then.
--
Regards,

Diez B. Roggisch
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.