Python lesson please

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Nov 6 21:54:16 EST 2011


On Sun, 06 Nov 2011 13:14:43 -0500, gene heskett wrote:

> 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.

<raises eyebrow>

Presumably the script should be working. If it is known to be not 
working, then you probably need to fix a lot more than just indentation.

If this is "pre-alpha, doesn't even compile" software, then good luck, 
you'll need to read the source and understand it to make it work. It's 
not sufficient to just get it to a point where you can say "Cool, it 
compiles!" by fixing some indentation.

If this is supposed to be working, there's a reason why it's not working 
for you. Perhaps you are trying to use it with the wrong version of 
Python. Perhaps the download is corrupted. Fix those before mangling 
indentation in random ways: start with a fresh, uncorrupted download. 
Check that the md5 sum matches that provided by the download site 
(assuming they provide one). Find out what version of Python is 
supported, and use that.


> This line looks suspect to me:
>  rootdir = sys.argv[1]

What makes you think that line is suspect? It looks fine to me.


> And I have a suspicion it is null on a linux box.

This is Python, not bash. Sys arguments are not filled in with "null", 
whatever you think "null" is. (The None built-in? The empty string?)

Have you tried giving the script an argument when you call it? If in 
doubt, call it with "." (the current directory) as argument.

My wild guess is that you actually need to supply a meaningful directory 
path before the script will do anything, and until then, it will silently 
fail. Which is terrible design.


> How can I fix that best?

If it's not broken, it doesn't need to be fixed. Don't make assumptions 
about what code needs to be fixed based on nothing more than gut feeling.



-- 
Steven



More information about the Python-list mailing list