[Tutor] question about looping.

Carlos Hanson chanson at ttsd.k12.or.us
Fri Oct 6 16:38:00 CEST 2006


Doug Potter wrote:
> Hi,
> 
> I at trying to create a bunch of text files in a single directory on a 
> Linux system,
> something like this.
> 
> import os
> 
> routers = ['adnc-6321', 'adnp-2341', 'adnw-2632']
> 
> for i in routers:
>     os.system('/bin/touch' %s) % i
> 
> of course this dosn't work.

try using the following:

for i in routers:
	os.system('/bin/touch %s' % i)

> Is there a simple way to get this done?

You can also use the builtin file object:

for i in routers:
	f = file(i, 'w')
	f.close()

> Thanks for your time.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Carlos Hanson
Web Specialist
Tigard-Tualatin School District
503.431.4053


More information about the Tutor mailing list