In article <4f7d125a-2713-4b57-a108-2a56ae653...@h3g2000yqe.googlegroups.com>, Denhua <dennisach...@gmail.com> 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\x00\x00\x00\x00\x00\x00b'] > [root@Inferno html]# > > > What's going on? Thanks for your help, > Dennis Step 1 in debugging any problem -- try to isolate the smallest possible test case. In your example, can you figure out if the weirdness is happening in f.write(), or in what is being passed to f.write()? Try breaking it down into something like: > output = "\n".join(newlist) > print output > f.write(output) > f.close() Next, figure out if it happens whenever you write() to a file, or only if you write() after you do a truncate(). Once you can answer those questions, you'll have a much smaller problem to try and solve. -- http://mail.python.org/mailman/listinfo/python-list