writing output to file

Emile van Sebille emile at fenx.com
Thu Jul 11 20:00:56 EDT 2002


> flout = open('/tmp/otherfile', 'w')
> for line in open('/etc/passwd').readlines() :
>     if line.strip()[0] == '#': continue


And if you're dealing with files that may have blank lines:
    if line.strip()[:1] in ('', '#'): continue
has an advantage of not failing on resulting zero length strings.

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list