[Novalug] Learning Python ???

greg pryzby greg@pryzby.org
Sat Mar 23 17:31:17 EDT 2013


Is there GNU indent and PEP8 style you can apply? Back in the day we had a
wrapper to ci (SCCS and RCS) that would format the code before checking it
in. On checkout I had a command to format it as I liked to read/write. The
idea was all code checked it was stylistically the same so diffs were
meaningful. We used K&R which is pretty close to what my code looked like.

A quick search showed Python people frowned in a tool and instead wanted
you yo read and apply the guide but not blindly because sometimes the guide
wasn't quite right.

http://stackoverflow.com/questions/9242748/programmatic-python-source-formatter

Just what I need in my life, another religious war :)

I am not sure anything is easier than Perl 3 but we will see. Yes my Perl
coding is from the mid90s

On Mar 23, 2013 4:37 PM, "Jason van Gumster" <jason@handturkeystudios.com>
wrote:

>
> Michael Henry <lug-user@drmikehenry.com> wrote:
>
> > On 03/23/2013 07:15 AM, greg pryzby wrote:
> > > On Mar 22, 2013 10:40 PM, "James Ewing" <jecottrell3@comcast.net>
> wrote:
> > > > More to the point, Python itself counts a tab as eight spaces. Game
> > Over.
> > >
> > > Not that I don't believe you but please point to doc that says
> > > that and what happens to Python if it isn't 8. If it was a
> > > hard fast rule Python would require tabs only for whitespace
> > > and a tab would have to be 8.
> >
> > Here is how Python treats indentation in source code:
> > http://docs.python.org/2/reference/lexical_analysis.html#indentation
> >
> > The relevant portion is:
> > """
> > First, tabs are replaced (from left to right) by one to eight
> > spaces such that the total number of characters up to and
> > including the replacement is a multiple of eight (this is
> > intended to be the same rule as used by Unix). The total number
> > of spaces preceding the first non-blank character then
> > determines the line’s indentation.
> > """
> >
> > Tab size matters only when mixing spaces and tabs for
> > indentation, but when mixing occurs, Python always uses a tab
> > size of 8 so that the indentation level is unambiguous.
>
> It's should also be noted that this quote is taken from the Python2
> documentation. Python developers recommend that you adhere to the PEP8[1]
> style
> guide for code. In that specification, spaces are strongly recommended over
> tabs[2], especially for new projects.
>
> On a separate note, I don't think migrating code/projects from one
> language to
> another is a particularly great way to learn... doing so often means you
> miss
> out on the beneficial idiosyncracies of the language. To use a spoken
> language
> metaphor, you'll end up writing Python with a Perl accent. Not only is this
> "wrong" in some regards, but it also makes it more difficult for you to get
> help from people who are experienced in the language you're trying to
> learn.
>
> My suggestion would be to pick a project to which Python is either uniquely
> suited or specifically required (for example, many graphics applications
> use
> Python as the sole - or at least primary - integrated scripting language).
> If
> you take that approach along with a primer from python.org, you should be
> able
> to get up to speed pretty quickly. Once you get by the whole whitespace
> thing, Python is quite possibly one of the dirt-simplest languages to
> learn. It
> can be quite a treat to use.
>
>   -Jason
>
> [1] http://www.python.org/dev/peps/pep-0008/
> [2] http://www.python.org/dev/peps/pep-0008/#tabs-or-spaces
> _______________________________________________
> Novalug mailing list
> Novalug@calypso.tux.org
> http://calypso.tux.org/mailman/listinfo/novalug
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.firemountain.net/pipermail/novalug/attachments/20130323/6033ebc5/attachment.htm>


More information about the Novalug mailing list