Re: [SPAM: 3.500] Re: [pygame] This one baffles me
On Wed, May 20, 2009 at 9:13 AM, Yanom Mobis ya...@rocketmail.com wrote: i guess i'll use spaces for my next program. But why exactly are spaces better? the article just said that was the standard On Wed, May 20, 2009 at 09:20:16AM +1000, René Dudfield wrote: At this point, it's because most python code, and python programmers are using spaces, instead of tabs. However, be aware that it is a matter of taste/religion, and it's an age old internet argument, and so you're always going to get different people saying that one style is better than the other. For me, spaces are like mp3 files whilst tabs are like mod files. I like mod files better than mp3 files, but the problem is that sometimes mod files sound different when you play them on different platforms. Best, Chris. --- http://mccormick.cx
Re: [SPAM: 3.500] Re: [pygame] This one baffles me
Both, tabs and spaces, work. mixing them doesn't. So you must make sure you only use one. which one you choose is more or less a matter of taste as Chris wrote. However, since mixing spaces and tabs is a bad idea it would be good if all (python) programmers could agree on one or the other. I believe that's why there is the python style guide I linked to earlier. It sets a precedent/convention. You can of course say you don't care and follow your own style but it will make it harder and more annoying for others. Therefore I would urge you to use spaces in python programs. yours, //Lorenz On Wed, 20 May 2009 11:38:18 +0100, Chris McCormick ch...@mccormick.cx wrote: On Wed, May 20, 2009 at 9:13 AM, Yanom Mobis ya...@rocketmail.com wrote: i guess i'll use spaces for my next program. But why exactly are spaces better? the article just said that was the standard On Wed, May 20, 2009 at 09:20:16AM +1000, René Dudfield wrote: At this point, it's because most python code, and python programmers are using spaces, instead of tabs. However, be aware that it is a matter of taste/religion, and it's an age old internet argument, and so you're always going to get different people saying that one style is better than the other. For me, spaces are like mp3 files whilst tabs are like mod files. I like mod files better than mp3 files, but the problem is that sometimes mod files sound different when you play them on different platforms. Best, Chris.
Re: [SPAM: 3.500] Re: [pygame] This one baffles me
umm... well i got my editor to display spaces and tabs differently (tabs with an arrow) so i can see where i've accidentally used spaces. thanks anyway --- On Mon, 5/18/09, Nicholas Dudfield ndudfi...@gmail.com wrote: From: Nicholas Dudfield ndudfi...@gmail.com Subject: Re: [SPAM: 3.500] Re: [pygame] This one baffles me To: pygame-users@seul.org Date: Monday, May 18, 2009, 9:12 AM jug wrote: I think you forgot the newline: .replace(\n+ *4, \n\t) No cigar... not even close.. from __future__ import with_statement with open ('perforce_plugin.py', 'r+w') as fh: fixed_tabs = fh.read().expandtabs(4) fh.seek(0) fh.write(fixed_tabs) *expandtabs*(s, tabsize=8) expandtabs http://pydoc.org/1.6/string.html#-expandtabs(s [,tabsize]) - string Return a copy of the string s with all tab characters replaced by the appropriate number of spaces, depending on the current column, and the tabsize (default 8).
Re: [SPAM: 3.500] Re: [pygame] This one baffles me
You should use 4 spaces and no tabs. The only exception is when you are modifying old files that already are using tabs. new files should use 4 spaces per indentation level. You can read up on this kind of stuff in the python style guide: http://www.python.org/dev/peps/pep-0008/ yours //Lorenz Yanom Mobis wrote: umm... well i got my editor to display spaces and tabs differently (tabs with an arrow) so i can see where i've accidentally used spaces. thanks anyway --- On *Mon, 5/18/09, Nicholas Dudfield /ndudfi...@gmail.com/* wrote: From: Nicholas Dudfield ndudfi...@gmail.com Subject: Re: [SPAM: 3.500] Re: [pygame] This one baffles me To: pygame-users@seul.org Date: Monday, May 18, 2009, 9:12 AM jug wrote: I think you forgot the newline: .replace(\n+ *4, \n\t) No cigar... not even close... from __future__ import with_statement with open ('perforce_plugin.py', 'r+w') as fh: fixed_tabs = fh.read().expandtabs(4) fh.seek(0) fh.write(fixed_tabs) *expandtabs*(s, tabsize=8) expandtabs http://pydoc.org/1.6/string.html#-expandtabs(s [,tabsize]) - string Return a copy of the string s with all tab characters replaced by the appropriate number of spaces, depending on the current column, and the tabsize (default 8).
Re: [SPAM: 3.500] Re: [pygame] This one baffles me
i guess i'll use spaces for my next program. But why exactly are spaces better? the article just said that was the standard --- On Tue, 5/19/09, Lorenz Quack d...@amberfisharts.com wrote: From: Lorenz Quack d...@amberfisharts.com Subject: Re: [SPAM: 3.500] Re: [pygame] This one baffles me To: pygame-users@seul.org Date: Tuesday, May 19, 2009, 5:01 PM You should use 4 spaces and no tabs. The only exception is when you are modifying old files that already are using tabs. new files should use 4 spaces per indentation level. You can read up on this kind of stuff in the python style guide: http://www.python.org/dev/peps/pep-0008/ yours //Lorenz Yanom Mobis wrote: umm... well i got my editor to display spaces and tabs differently (tabs with an arrow) so i can see where i've accidentally used spaces. thanks anyway --- On *Mon, 5/18/09, Nicholas Dudfield /ndudfi...@gmail.com/* wrote: From: Nicholas Dudfield ndudfi...@gmail.com Subject: Re: [SPAM: 3.500] Re: [pygame] This one baffles me To: pygame-users@seul.org Date: Monday, May 18, 2009, 9:12 AM jug wrote: I think you forgot the newline: .replace(\n+ *4, \n\t) No cigar... not even close... from __future__ import with_statement with open ('perforce_plugin.py', 'r+w') as fh: fixed_tabs = fh.read().expandtabs(4) fh.seek(0) fh.write(fixed_tabs) *expandtabs*(s, tabsize=8) expandtabs http://pydoc.org/1.6/string.html#-expandtabs(s [,tabsize]) - string Return a copy of the string s with all tab characters replaced by the appropriate number of spaces, depending on the current column, and the tabsize (default 8).
Re: [SPAM: 3.500] Re: [pygame] This one baffles me
At this point, it's because most python code, and python programmers are using spaces, instead of tabs. cheers, On Wed, May 20, 2009 at 9:13 AM, Yanom Mobis ya...@rocketmail.com wrote: i guess i'll use spaces for my next program. But why exactly are spaces better? the article just said that was the standard
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 cp for the console... On Sun, May 17, 2009 at 6:41 PM, Greg Ewing greg.ew...@canterbury.ac.nzwrote: 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
Re: [SPAM: 3.500] Re: [pygame] This one baffles me
I think you forgot the newline: .replace(\n+ *4, \n\t)
Re: [SPAM: 3.500] Re: [pygame] This one baffles me
jug wrote: I think you forgot the newline: .replace(\n+ *4, \n\t) No cigar... not even close.. from __future__ import with_statement with open ('perforce_plugin.py', 'r+w') as fh: fixed_tabs = fh.read().expandtabs(4) fh.seek(0) fh.write(fixed_tabs) *expandtabs*(s, tabsize=8) expandtabs http://pydoc.org/1.6/string.html#-expandtabs(s [,tabsize]) - string Return a copy of the string s with all tab characters replaced by the appropriate number of spaces, depending on the current column, and the tabsize (default 8).
Re: [SPAM: 3.500] Re: [pygame] This one baffles me
Wow, thanks Ahem: http://yellow.bikeshed.com/ There's no need for everyone to jump in and start offering solutions to a simple problem. There's lots of different ways to solve it. People have different opinions on what is the best way. But irregardless, I'm pretty sure the GP knows how to do it now. -Tyler On Mon, May 18, 2009 at 7:12 AM, Nicholas Dudfield ndudfi...@gmail.com mailto:ndudfi...@gmail.com wrote: jug wrote: I think you forgot the newline: .replace(\n+ *4, \n\t) No cigar... not even close.. from __future__ import with_statement with open ('perforce_plugin.py', 'r+w') as fh: fixed_tabs = fh.read().expandtabs(4) fh.seek(0) fh.write(fixed_tabs) *expandtabs*(s, tabsize=8) expandtabs http://pydoc.org/1.6/string.html#-expandtabs(s [,tabsize]) - string Return a copy of the string s with all tab characters replaced by the appropriate number of spaces, depending on the current column, and the tabsize (default 8). -- Visit my blog at http://oddco.ca/zeroth/zblog
Re: [SPAM: 3.500] Re: [pygame] This one baffles me
On Tue, May 19, 2009 at 12:29 AM, Tyler Laing trinio...@gmail.com wrote: Ahem: http://blue.bikeshed.com/ There's no need for everyone to jump in and start offering solutions to a simple problem. There's lots of different ways to solve it. People have different opinions on what is the best way. But irregardless, I'm pretty sure the GP knows how to do it now. -Tyler ... except if the offered solutions are wrong, or there is a better way that people might be interested in, or people just want to have a discussion in a place where they can talk about whatever they want to. The replace(..., \t) solutions insert tabs, not replace tabs with spaces. So they're not good. Should write the result to a temporary file, then do a move from the temporary file into the new file. This way if there is a bug in your code half way through writing it won't wipe out the original... Also move is an atomic operation, whereas writing to the file you just read from can cause all sorts of problems. Say something tries to read your file halfway through your write, then they will get half a file back... whereas if you write to a temporary file then move it, every other program reading your file will never get a corrupt file. cu,
Re: [SPAM: 3.500] Re: [pygame] This one baffles me
Both good points. I stand corrected. Its not like anyone /has/ to listen to me... just that we reached 8 different solutions by my count, with them starting to use more obscure syntax and functions... Just wanted to point out that it was starting to get a bit ridiculous, thats all. :) -Tyler On Mon, May 18, 2009 at 2:52 PM, René Dudfield ren...@gmail.com wrote: On Tue, May 19, 2009 at 12:29 AM, Tyler Laing trinio...@gmail.com wrote: Ahem: http://blue.bikeshed.com/ There's no need for everyone to jump in and start offering solutions to a simple problem. There's lots of different ways to solve it. People have different opinions on what is the best way. But irregardless, I'm pretty sure the GP knows how to do it now. -Tyler ... except if the offered solutions are wrong, or there is a better way that people might be interested in, or people just want to have a discussion in a place where they can talk about whatever they want to. The replace(..., \t) solutions insert tabs, not replace tabs with spaces. So they're not good. Should write the result to a temporary file, then do a move from the temporary file into the new file. This way if there is a bug in your code half way through writing it won't wipe out the original... Also move is an atomic operation, whereas writing to the file you just read from can cause all sorts of problems. Say something tries to read your file halfway through your write, then they will get half a file back... whereas if you write to a temporary file then move it, every other program reading your file will never get a corrupt file. cu, -- Visit my blog at http://oddco.ca/zeroth/zblog
Re: [SPAM: 3.500] Re: [pygame] This one baffles me
RB[0] wrote: 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) No, that only replaces the first group of 4 spaces on each line, and removes the newlines as well. The obvious way to do this properly is to loop over the lines and use the expandtabs() string method. -- Greg
Re: [SPAM: 3.500] Re: [pygame] This one baffles me
Greg Ewing wrote: RB[0] wrote: 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) No, that only replaces the first group of 4 spaces on each line, and removes the newlines as well. The obvious way to do this properly is to loop over the lines and use the expandtabs() string method. Oh, and write a test first
Re: [SPAM: 3.500] Re: [pygame] This one baffles me
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