[Tutor] proxy switcher - was Re: I love python / you guys :)
Luke Paireepinart
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[0] == '#':
> line = line[1:]
> else:
> line = '#' + line
> output.write(line)
>
Also, you didn't define 'output' anywhere. Is this an implicit declaration
via the 'with' syntax?
Thanks,
-Luke
>
>
S.
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091116/1d1cec20/attachment.htm>
More information about the Tutor
mailing list