[Tutor] proxy switcher - was Re: I love python / you guys :)
rabidpoobear at gmail.com
Mon Nov 16 15:52:34 CET 2009
> Here's what I knocked up over lunch. It doesn't cover the moving of
> the file, I don't like that it's deep-nested, and I've not tested it,
> but I welcome criticism and feedback:
> files = ['file1', 'file2', 'file3', 'file4']
> settings = ['export http_proxy=', 'ftp_proxy=']
> for file in files:
> with open(file, 'rw') as file:
Does this actually work?
I didn't think you could open files as reading and writing?
also you're shadowing the 'file' var, which might be confusing to beginners,
as it's not the same file as in the outer for loop.
Also, 'with' is a 3.0 keyword, right? That's pretty interesting syntax,
I've never seen it before, but I haven't used 3.x yet.
> for line in file:
> for setting in settings:
> if setting in line:
> if line == '#':
> line = line[1:]
> line = '#' + line
Also, you didn't define 'output' anywhere. Is this an implicit declaration
via the 'with' syntax?
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor