[Tutor] question about looping.
Hugo González Monteverde
hugonz-lists at h-lab.net
Sun Oct 8 19:11:56 CEST 2006
Doug Potter wrote:
> for i in routers:
> os.system('/bin/touch' %s) % i
>
> of course this dosn't work.
>
> Is there a simple way to get this done?
Yep, someone already answered that you can create the file in write mode
and then close it, but I wanted to add a little more in why your
solution doesn't work.
You're not interpolating the filename INTO the os.system string
The following would work
for i in routers:
os.system('/bin/touch %s'%1)
Granted, you should also provide a filename with a full path for simplicity.
HTH
Hugo
More information about the Tutor
mailing list