[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [SPAM: 3.500] Re: [pygame] This one baffles me



Yeah, if you want to convert just the tabs at the start of a line, you would need to do:
print open("myfile.py").read().replace("\n"+" "*4, "\t") or whichever line ending you have on your system...

but actually I would do a 3 liner that is more helpful, IMO:

f = open("myfile.py", "rw")
f.write(f.read.replace("\n" + " "*4, "\t"))
f.close()

I think "rw" is what you want there, but I haven't worked with it in a while, but basically that will just load your file, convert and then resave it, so you don't have to c&p for the console...

On Sun, May 17, 2009 at 6:41 PM, Greg Ewing <greg.ewing@xxxxxxxxxxxxxxxx> wrote:
Casey Duncan wrote:
Here's the moral-equivalent one-liner in Python:

print open("myfile.py").read().replace(" "*4, "\t")

Note that this is not exactly the right way to
expand tabs, since it doesn't take account of
the position in the line at which the block of
spaces starts. But it's okay if all you care
about is leading indentation.

--
Greg