Re: Code reformater?

2007-01-22 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Vincent Delporte wrote:

 On Sun, 21 Jan 2007 14:15:46 +1100, Steven D'Aprano
 [EMAIL PROTECTED] wrote:
Still, it is better not to lose the indentation in the first place.
 
 Thanks for the tips. But it does happen when copy/pasting code from
 either a web page or an e-mail that TABs are messed up, which is not a
 problem with other languages, but is a problem with Python. Too bad.

Well then don't use code from people using TABs.  If it's indented by four
spaces per level, like suggested by the style guide, there's no problem
with TABs.

Ciao,
Marc 'BlackJack' Rintsch

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code reformater?

2007-01-21 Thread Vincent Delporte
On Sun, 21 Jan 2007 14:15:46 +1100, Steven D'Aprano
[EMAIL PROTECTED] wrote:
Still, it is better not to lose the indentation in the first place.

Thanks for the tips. But it does happen when copy/pasting code from
either a web page or an e-mail that TABs are messed up, which is not a
problem with other languages, but is a problem with Python. Too bad.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code reformater?

2007-01-20 Thread Mario Wehbrink
Vincent Delporte schrieb in comp.lang.python:

Hi

   When I copy/paste Python code from the web, every so often,
 the TABs are wrong, which means that the code won't work and I have to
 manually reformat the code.

 Is there a code reformater that can parse the code to make it right?

It may help to look at the settings of your editor. I think Vim (and
surely emacs) can help you with that.

(look at :help retab, paste, expandtab in (g)Vim)

Mario


-- 
Mario Wehbrink
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code reformater?

2007-01-20 Thread Siggi

Vincent Delporte wrote:
 Hello

 When I copy/paste Python code from the web, every so often,
 the TABs are wrong, which means that the code won't work and I have to
 manually reformat the code.

 Is there a code reformater that can parse the code to make it right?

 Thanks.

Maybe my thread help: code formatter, 08/01/2007 helps a little? Here are
some of the answers:

*
Why don't you just write one? :)
Seriously: Try.
*
Tools\scripts\reindent.py in your Python distribution.
*
Why, yes, there is:
 http://lacusveris.com/PythonTidy/PythonTidy.python
*
tabnanny ?


siggi




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code reformater?

2007-01-20 Thread Gabriel Genellina

At Saturday 20/1/2007 14:37, Siggi wrote:


 When I copy/paste Python code from the web, every so often,
 the TABs are wrong, which means that the code won't work and I have to
 manually reformat the code.

 Is there a code reformater that can parse the code to make it right?

 Thanks.

Maybe my thread help: code formatter, 08/01/2007 helps a little? Here are
some of the answers:

*
Why don't you just write one? :)
Seriously: Try.
*
Tools\scripts\reindent.py in your Python distribution.
*
Why, yes, there is:
 http://lacusveris.com/PythonTidy/PythonTidy.python
*
tabnanny ?


As the indentation *is* significant in python, none of the above can 
help if you lose the indentation. Try to reconstruct this:


def foo():
if a0:
if b0:
print 1
print 2
else:
return 3
return 4

The tools may help to make the indentation consistent (tabs/8 
spaces/4 spaces/2 spaces mixed) or look better, but not to make it right.



--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Code reformater?

2007-01-20 Thread Steven D'Aprano
On Sat, 20 Jan 2007 23:51:24 -0300, Gabriel Genellina wrote:

 As the indentation *is* significant in python, none of the above can 
 help if you lose the indentation. Try to reconstruct this:
 
 def foo():
 if a0:
 if b0:
 print 1
 print 2
 else:
 return 3
 return 4
 
 The tools may help to make the indentation consistent (tabs/8 
 spaces/4 spaces/2 spaces mixed) or look better, but not to make it right.


Sure -- but a heuristic that gets it right *sometimes* may still be
useful, provided the user knows that the code may not be indented
correctly.

There are lots of legal Python blocks where the indentation CAN be
reconstructed correctly, and only a relatively small proportion where it
can't -- the tool could do its best, and warn the user when there are
indents that can't be dealt with. Or even refuse the temptation to guess,
but re-indent whatever parts of the code it is sure about.

Still, it is better not to lose the indentation in the first place.



-- 
Steven.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code reformater?

2007-01-20 Thread Gabriel Genellina

At Sunday 21/1/2007 00:15, Steven D'Aprano wrote:


On Sat, 20 Jan 2007 23:51:24 -0300, Gabriel Genellina wrote:

 As the indentation *is* significant in python, none of the above can
 help if you lose the indentation. Try to reconstruct this:

 def foo():
 if a0:
 if b0:
 print 1
 print 2
 else:
 return 3
 return 4

 The tools may help to make the indentation consistent (tabs/8
 spaces/4 spaces/2 spaces mixed) or look better, but not to make it right.


Sure -- but a heuristic that gets it right *sometimes* may still be
useful, provided the user knows that the code may not be indented
correctly.

There are lots of legal Python blocks where the indentation CAN be
reconstructed correctly, and only a relatively small proportion where it
can't --


I'd say absolutely the opposite. Try the example above. Or this one, simpler:

def foo():
if a0:
if b0:
print 1
print 2

Which level should be 'print 2' assigned to? There are 3 choices. 
What if there is a third print? There are 3, 2, or 1 possibilities, 
depending on where you put the previous one. The same for any other 
statement below.
The problem is, after a colon, you know that a new block begins and 
you must indent, but you don't know when that block ends except in a 
few cases (an else clause, by example, and only if there was a single 
preceding if).



the tool could do its best, and warn the user when there are
indents that can't be dealt with. Or even refuse the temptation to guess,
but re-indent whatever parts of the code it is sure about.


...almost nothing, I'm afraid... :(


Still, it is better not to lose the indentation in the first place.


Sure!


--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

-- 
http://mail.python.org/mailman/listinfo/python-list

Code reformater?

2007-01-19 Thread Vincent Delporte
Hello

When I copy/paste Python code from the web, every so often,
the TABs are wrong, which means that the code won't work and I have to
manually reformat the code.

Is there a code reformater that can parse the code to make it right?

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code reformater?

2007-01-19 Thread Ben Finney
Vincent Delporte [EMAIL PROTECTED] writes:

 When I copy/paste Python code from the web, every so often, the TABs
 are wrong, which means that the code won't work and I have to
 manually reformat the code.

 Is there a code reformater that can parse the code to make it right?

Indentation is necessary for the syntax in Python. If that information
is lost, it can't be reliably recreated.

-- 
 \   People come up to me and say, 'Emo, do people really come up |
  `\ to you?'  -- Emo Philips |
_o__)  |
Ben Finney

-- 
http://mail.python.org/mailman/listinfo/python-list