Re: Reading and writing to a file creates null characters

2012-01-13 Thread Denhua
On Jan 12, 6:21 pm, MRAB wrote: > On 12/01/2012 22:26, Denhua wrote: > > > > > > > > > Hi, > > > I've got a file which I'd like to read, modify and write. > > > # file contents > > a > > b > > c > > d > > > My script reads the file contents into a list and rotates the list and > > writes it back t

Re: Reading and writing to a file creates null characters

2012-01-12 Thread MRAB
On 12/01/2012 22:26, Denhua wrote: Hi, I've got a file which I'd like to read, modify and write. # file contents a b c d My script reads the file contents into a list and rotates the list and writes it back to the same file. Problem is that the output contains null characters. I don't know whe

Re: Reading and writing to a file creates null characters

2012-01-12 Thread Roy Smith
In article <4f7d125a-2713-4b57-a108-2a56ae653...@h3g2000yqe.googlegroups.com>, Denhua wrote: > [omitted] > f.write("\n".join(newlist)) > f.close() > > # output > > [root@Inferno html]# python rotate.py > ['b', 'c', 'd', 'a'] > [root@Inferno html]# python rotate.py > ['c', 'd', 'a', '\x00\x00\

Reading and writing to a file creates null characters

2012-01-12 Thread Denhua
Hi, I've got a file which I'd like to read, modify and write. # file contents a b c d My script reads the file contents into a list and rotates the list and writes it back to the same file. Problem is that the output contains null characters. I don't know where they are coming from. #!/usr/bin/