Python lesson please
Cameron Simpson
cs at zip.com.au
Sun Nov 6 15:34:29 EST 2011
On 06Nov2011 13:14, gene heskett <gheskett at wdtv.com> wrote:
| Greetings experts:
|
| I just dl'd the duqu driver finder script from a link to NSS on /., and
| fixed enough of the tabs in it to make it run error-free. At least python
| isn't having a litter of cows over the indentation now.
|
| But it also runs instantly on linux.
|
| This line looks suspect to me:
| rootdir = sys.argv[1]
|
| And I have a suspicion it is null on a linux box.
That line collects the first command line argument. sys.argv is the
command line; argv[0] is the command name, argv[1] the first argument
and so forth.
Also, if there is no first argument then trying to access argv[1] will
raise an IndexError exception, not return a null value.
If you're this new to python, note that easy debugging statements can be
written:
print >>sys.stderr, "the value of foo is", foo
and so forth.
Perhaps more relevantly:
If you have unmangled a lot of tabs, remember that control flow is
indentation based in python, and you may have broken some logic.
(For this reason a number of us set our editors to work only in spaces).
Anyway, while changing:
statement1
statement2
into:
statement1
statement2
will usually make python complain, changing:
if some test here:
statement1
statement2
into:
if some test here:
statement1
statement2
just means that statement2 is no longer inside the if-statement, and
elicit no compaints. But will elicit bugs!
Cheers,
--
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/
The ZZR-1100 is not the bike for me, but the day they invent "nerf" roads
and ban radars I'll be the first in line......AMCN
More information about the Python-list
mailing list