[Tutor] format a file

Lie Ryan lie.1296 at gmail.com
Thu Feb 26 12:00:01 CET 2009


Try thinking what happens when you do this:

line = 'this is a reaaaaaaaaaaaaaaaaaaaallly long lineeeee\n'
first = line[:20]
second = line[20:]
print first
print second

.
.
.
.
.
.
.
.
.
.

Have you got it? The first would contain "this is a reaaaaaaaa" and the 
second "aaaaaaaaaaaallly long lineeeee\n"

When you try to write to the file:

de.write(first)
de.write(second)

why isn't there a new line between the first and second?

Also, I think you should realize that with how you do it now, you may put 
line breaks in between words. Better to split on space line.split(' ') 
then ' '.join(first) + '\n' it together again.



More information about the Tutor mailing list