how to format a python source file with tools?

  • Thread starter §õ¥Õ¡A¦r¤@¤é
  • Start date
8

84715175

or is it possible for large source files?

<p> <strong><a title="sport jersey" href="http://www.jerseysup.com"
target="sport jersey">sport jersey</a></strong>
<a title="sport jersey"
href="http://www.sport-jersey.net" target="sport
jersey"><strong>sports jersey </strong></a><strong> </strong><a
title="ugg women" href="http://www.uggwomen.net" target="ugg
women"><strong>uggboot </strong></a><strong> </strong><a title="nike
market " href="http://www.nike-market.com" target="nike
market"><strong>nike</strong></a></p>
 
8

84715175

are you trying to format the file with the proper indentations?

<p> <strong><a title="sport jersey" href="http://www.jerseysup.com"
target="sport jersey">sport jersey</a></strong>
<a title="sport jersey"
href="http://www.sport-jersey.net" target="sport
jersey"><strong>sports jersey </strong></a><strong> </strong><a
title="ugg women" href="http://www.uggwomen.net" target="ugg
women"><strong>uggboot </strong></a><strong> </strong><a title="nike
market " href="http://www.nike-market.com" target="nike
market"><strong>nike</strong></a></p>
 
M

Marco Mariani

?? said:
or is it possible for large source files?


Google for polystyle.

It's a tool that reformats a program (in several languages) using an
example you must provide (let's call it a "style sheet", written in
Python or whatever) of how you would want to format it.

You can then reformat any python program according to your "style sheet"
 
Æ

æŽç™½ï¼Œå­—一日

Is what possible? What do you want the tool to do?

--
 \           “I do not believe in forgiveness as it is preached by the |
  `\        church. We do not need the forgiveness of God, but of each |
_o__)                    other and of ourselves.†—Robert G. Ingersoll |
Ben Finney

sometimes i need to merge some code snippets from files into a file,
and when time comes to do this merge, i always find it difficult to
reformat the python code
because after pasting and copy, the code indentation different from
one to another.
and it is the tedious job for us to manually move the code from one
segment to another.

so i would like to have a tool to intelligently format the code for me
and make the code more beautiful
and automated.
 
§

§õ¥Õ¡A¦r¤@¤é

Google for polystyle.

It's a tool that reformats a program (in several languages) using an
example you must provide (let's call it a "style sheet", written in
Python or whatever) of how you would want to format it.

You can then reformat any python program according to your "style sheet"

greate!
 
D

Diez B. Roggisch

æŽç™½ï¼Œå­—一日 said:
sometimes i need to merge some code snippets from files into a file,
and when time comes to do this merge, i always find it difficult to
reformat the python code
because after pasting and copy, the code indentation different from
one to another.
and it is the tedious job for us to manually move the code from one
segment to another.

so i would like to have a tool to intelligently format the code for me
and make the code more beautiful
and automated.

This is not possible. Consider the following situation:


code a:


if something:
do_something()


code b:

if anything:
do_something_else()


No lets say you copy b after a. At which level should it be? Like this


if something:
do_something()

if anything:
do_something_else()


Or like this?

if something:
do_something()

if anything:
do_something_else()



Both are semantically radically different, and only you know which one
is the right one.

What my editor (emacs) allows, and other IDEs/editors as well is to mark
blocks, and shift these wholesome left or right, to get the desired
indention level.

The only thing that migh be automatized after a piece of code is valid
is normalization, like de-tabifying or making everything based on 4
space characters indention. No idea if there is something out there that
does that.

Diez
 
N

Neil Cerutti

The only thing that migh be automatized after a piece of code
is valid is normalization, like de-tabifying or making
everything based on 4 space characters indention. No idea if
there is something out there that does that.

In vim, you can do something like:

:set tabstop=4
:set expandtab
:retab
 
G

gil_johnson

so i would like to have a tool to intelligently format the code for me
and make the code more beautiful
and automated.

This is not possible. Consider the following situation:

Both are semantically radically different, and only you know which one
is the right one.

I have to agree with Diez, there is no way to automate this. Some
human intervention is needed. What I would like is an editor that will
indicate what Python will consider a logical block (and sub-block, and
sub-sub-block, etc.)
It's complicated. I've tried to think of a way to do it, and have
gotten lost after a few changes of indentation.
Does anyone know of such a thing?
I miss curly braces with an editor that will highlight matching
parentheses, braces, etc.
Gil
 
F

Falcolas

This is not possible. Consider the following situation:
[...]
Both are semantically radically different, and only you know which one
is the right one.
Diez

I have to agree with Diez, there is no way to automate this. Some
human intervention is needed. What I would like is an editor that will
indicate what Python will consider a logical block (and sub-block, and
sub-sub-block, etc.)
It's complicated. I've tried to think of a way to do it, and have
gotten lost after a few changes of indentation.
Does anyone know of such a thing?
I miss curly braces with an editor that will highlight matching
parentheses, braces, etc.
Gil

At least with Windows, you get a number of scripts included in your
Python install - under the python directory/tools/scripts. There are
several scripts here which are intended to help with indentation
issues - such as reindent and pindent. Those might help you out some.

Nonetheless, it would be better to implement coding standards that
everyone can stick to.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,968
Members
47,524
Latest member
ecomwebdesign

Latest Threads

Top