Fwd: Python new user question - file writeline error

Gabriel Genellina gagsl-py at yahoo.com.ar
Thu Feb 8 12:05:51 EST 2007


On 8 feb, 12:41, "Shawn Milo" <S... at Milochik.com> wrote:

> I have come up with something that's working fine. However, I'm fairly
> new to Python, so I'd really appreciate any suggestions on how this
> can be made more Pythonic.

A few comments:

You don't need the formatDatePart function; delete it, and replace
newDate = ",%s-%s-%s," % (yearNum,monthNum,dayNum)
with
newDate = ",%04.4d-%02.2d-%02.2d," % (yearNum,monthNum,dayNum)

and before:
                dayNum, monthNum, yearNum = [int(num) for num in
someDate[1:-1].split('/')]

And this: outfile.writelines(line)
should be: outfile.write(line)
(writelines works almost by accident here).

You forget again to use () to call the close methods:
infile.close()
outfile.close()

I don't like the final replace, but for a script like this I think
it's OK.

--
Gabriel Genellina




More information about the Python-list mailing list