Re: What was the project that made you feel skilled in Python?

2013-05-22 Thread Ben Finney
Ned Batchelder  writes:

> as you moved from exercises like those in Learn Python the Hard Way,
> up to your own self-guided work on small projects, what project were
> you working on that made you feel independent and skilled?  What
> program first felt like your own work rather than an exercise the
> teacher had assigned?

I wanted to simulate a particular board game, and had others in mind
with some common mechanics.

This resulted in a library for rolling dice in different combinations,
and looking up result tables https://pypi.python.org/pypi/alea>.

Eventually I wanted to extend it to know about custom decks of cards,
and the different ways those are handled in board games.

The unifying theme was a library of routines for simulating the random
elements (dice, cards, tables, spinners, etc.) in any board game.

A little over-engineered, I'll freely admit. But it did give me a sense
of being at home in Python and knowing that this is a good language for
getting things done the right way.

-- 
 \ “Creativity can be a social contribution, but only in so far as |
  `\society is free to use the results.” —Richard Stallman |
_o__)          |
Ben Finney

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


Re: What was the project that made you feel skilled in Python?

2013-05-23 Thread Ben Finney
Chris Angelico  writes:

> Ben Finney  wrote:
> > This resulted in a library for rolling dice in different
> > combinations, and looking up result tables
> > https://pypi.python.org/pypi/alea>.
>
> Fun fun! Of course, when I hear "rolling dice in different
> combinations", my mind immediately turns to Dungeons and Dragons,
> where it's plausible to roll d20+7, then roll 2d8+d6+12 to figure out
> how much damage you did...

Yeah, and lots of board games use custom dice with faces specific to
that game (symbols, non-consecutive numbers, etc.), so the Die class
allows the faces to be any object the application needs.

> But the hard part of board games is usually the board.

A lot of the board games I'm intrigued by don't have much of a board;
they use custom cards and tokens and (maybe) dice, and the “board” is an
abstraction of where all the pieces are on the table.

> I used to spend ages trying to draw up a half-decent board, and ended
> up giving up. By "simulate", I'm guessing you mean that you didn't
> actually draw anything of the sort?

Right. The (never completed) application was to simulate the mechanics
of that particular game so I could see how it would play out, not be an
interactive playable game.

I've long been aware there is an enormous amount of UI-programming work
involved with interactive playable games. My ambition for that work was
quenched from attempting it in my teenage years :-)

-- 
 \“With Lisp or Forth, a master programmer has unlimited power |
  `\ and expressiveness. With Python, even a regular guy can reach |
_o__)   for the stars.” —Raymond Hettinger |
Ben Finney

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


Python 3 and ‘python-daemon’ (was: [RELEASED] Python 2.7.5)

2013-06-05 Thread Ben Finney
Joshua Landau  writes:

> Don't take this list too seriously - some of those do have fully
> working and stable Python 3 packages that just aren't in pip, like
> python-daemon.

That's news to me, as the package maintainer. There's no official
‘python-daemon’ release for Python 3. What ‘python-daemon’ works in
Python 3?

-- 
 \ “We are not gonna be great; we are not gonna be amazing; we are |
  `\   gonna be *amazingly* amazing!” —Zaphod Beeblebrox, _The |
_o__)Hitch-Hiker's Guide To The Galaxy_, Douglas Adams |
Ben Finney

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


Re: Version Control Software

2013-06-12 Thread Ben Finney
cutems93  writes:

> I am looking for an appropriate version control software for python
> development, and need professionals' help to make a good decision.

> Currently I am considering four software: git, SVN, CVS, and
> Mercurial.

These days there is no good reason to use CVS nor Subversion for new
projects. They are not distributed (the D in DVCS), and they have
specific design flaws that often cause insidious problems with common
version control workflows. As a salient example, branching and merging
are so painful with these tools that many users have learned the
terrible habit of never doing it at all.

Bazaar, Git, and Mercurial are all excellent DVCS systems (and all have
excellent branching and merging support). For someone new to version
control, I would highly recommend Bazaar, or Mercurial if that's not an
option. I would not recommend Git for new work.

It helps that all of these are free software. Avoid proprietary tools
for development work, especially tools that control access to your data.

> What version control software do you like the most and why?

Bazaar. It has, in my experience, by far the easiest default workflow to
learn. It is also very flexible for the odd wrinkles in preferred
workflow that most beginners don't even know enough to realise they have.

(Examples of Bazaar features that make it IMO superior are: default to
view only the main-line revisions without the “merge noise” that would
happens with other VCSes; easily serve a branch from just about any
shared file storage; easily choose a centralised repository for
particular purposes without any other user needing to do anything
different).

Mercurial is relatively easy to learn, and full-featured; it is somewhat
more restrictive than Bazaar but not enough to recommend against.


Git is hugely capable and is the most popular, but still has some
annoying restrictions (e.g. it can't hide merged revisions, encouraging
poor practice like re-writing history when merging a branch).

But my main reason to recommend against Git is that its native interface
is far too baroque: it exposes its innards and requires the user to know
a huge range of internal concepts to avoid making mistakes.

You should be wary of GitHub, a very popular Git hosting site. It uses
what amount to proprietary protocols, which encourage using GitHub's
specific interface instead of native Git for your operations and hide a
lot of the needless complexity; but this results in a VCS repository
that is difficult to use *without* being tied to that specific site,
killing one of the best reasons to use a DVCS in the first place.

Gitorious is a Git hosting site that does not have this problem, and may
for that reason be a good choice for hosting your Git repositories. It
is also based on free software (unlike GitHub), so if the service goes
away for any reason, anyone else can produce a functionally identical
service from the same server code. This makes it a better bet for
hosting your repositories.

Neither Mercurial nor Bazaar suffer from Git's baroque complexity, and
with Bazaar's command interface being IME the easiest and most intuitive
to teach, I would recommend Bazaar for any new VCS user.


A sad caveat, though: Bazaar suffers from a foolishly limited
development pool (Canonical are the main copyright holder, and, instead
of accepting contributions under the same license they grant to others,
they obstinately insist on having special exclusive powers over the
code). Also, Bazaar's early versions did not impress large projects like
Linux or Python; improvements have long since erased the reasons for
that, but too late for widespread popularity.

So Bazaar's popularity never gained as much as Git or Mercurial. Worse,
development of Bazaar appears to have stagnated at Canonical — and,
because they insisted on being in a privileged copyright position,
no-one else is in a good position to easily carry on development.

Bazaar is still my recommendation of primary VCS tool, for its
flexibility, speed, wealth of plug-ins, ability to view revision history
sensible, and straightforward command interface. But you should go into
it aware that it may be a little more difficult to find fellow users of
Bazaar than of Mercurial.

-- 
 \   “The lift is being fixed for the day. During that time we |
  `\regret that you will be unbearable.” —hotel, Bucharest |
_o__)      |
Ben Finney

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


Re: My son wants me to teach him Python

2013-06-13 Thread Ben Finney
Steven D'Aprano  writes:

> I consider IDEs to be an attractive nuisance. It's like learning to be a 
> chef by putting food in a microwave and pushing the pre-set buttons. 

+1 QotW

-- 
 \“With Lisp or Forth, a master programmer has unlimited power |
  `\ and expressiveness. With Python, even a regular guy can reach |
_o__)   for the stars.” —Raymond Hettinger |
Ben Finney

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


Re: Debugging memory leaks

2013-06-14 Thread Ben Finney
rusi  writes:

> On Jun 14, 1:15 am, Giorgos Tzampanakis
>  wrote:
> > Am I the only one who thinks this is terrible advice?
>
> I would expect a typical desktop app to run for a couple of hours --
> maybe a couple of days.

Is a web browser a “typical desktop app”? A filesystem browser? An
instant messenger? A file transfer application? A podcatcher? All of
those typically run for months at a time on my desktop.

Any memory leak in any of those is going to cause trouble, please hunt
them all down with fire and exterminate with prejudice.

-- 
 \ “Experience is that marvelous thing that enables you to |
  `\   recognize a mistake when you make it again.” —Franklin P. Jones |
_o__)          |
Ben Finney

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


Re: RFD: rename comp.lang.python to comp.support.superhost

2013-06-14 Thread Ben Finney
Gene Heskett  writes:

> One old (78) farts take on this endless thread is that its a sign that 
> those who had it made in Greece

Please refrain from nationalistic slurs, it is not acceptable in this
community.

-- 
 \   “If you don't know what your program is supposed to do, you'd |
  `\ better not start writing it.” —Edsger W. Dijkstra |
_o__)      |
Ben Finney

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


Re: Don't feed the troll...

2013-06-14 Thread Ben Finney
"D'Arcy J.M. Cain"  writes:

> The answer is to always make sure that you include the previous poster
> in the reply as a Cc or To.

Dragging the discussion from one forum (comp.lang.python) to another
(every person's individual email) is obnoxious. Please don't.

> I have suggested this before but the push back I get is that then
> people would get two copies of the email, one to them and one to the
> list.

In my case, I don't want to receive the messages by email *at all*. I
participate in this forum using a non-email system, and it works fine so
long as people continue to participate in this forum.

Even for those who do participate by email, though, your approach is
broken:

> My answer is simple.  Get a proper email system that filters out
> duplicates.

The message sent to the individual typically arrives earlier (since it
is sent straight from you to the individual), and the message on the
forum arrives later (since it typically requires more processing).

But since we're participating in the discussion on the forum and not in
individual email, it is the later one we want, and the earlier one
should be deleted.

So at the point the first message arrives, it isn't a duplicate. The
mail program will show it anyway, because “remove duplicates” can't
catch it when there's no duplicate yet.

The proper solution is for you not to send that one at all, and send
only the message to the forum.

You do this by using your mail client's “reply to list” function, which
uses the RFC 3696 information in every mailing list message.

Is there any mail client which doesn't have this function? If so, use
your vendor's bug reporting system to request this feature as standard,
and/or switch to a better mail client until they fix that.

-- 
 \   “Timid men prefer the calm of despotism to the boisterous sea |
  `\of liberty.” —Thomas Jefferson |
_o__)  |
Ben Finney

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


Re: Debugging memory leaks

2013-06-15 Thread Ben Finney
rusi  writes:

> On Jun 15, 5:16 am, Ben Finney  wrote:
> > Is a web browser a “typical desktop app”? A filesystem browser? An
> > instant messenger? A file transfer application? A podcatcher? All of
> > those typically run for months at a time on my desktop.
> >
> > Any memory leak in any of those is going to cause trouble, please
> > hunt them all down with fire and exterminate with prejudice.
>
> Oh well -- I guess I am an old geezer who shuts my machine when I am
> done!

As do I. And when I power on the machine, it resumes exactly where it
left off: with the exact same contents of memory as when I pressed the
Suspend button.

That is, the memory leak will continue to accumulate as the run time of
the process continues.

> Yeah I know -- not so good for the disk though its good for the
> planet!

You can have both: a continuous session, and stop consuming power while
not using your machine.

-- 
 \ “It is far better to grasp the universe as it really is than to |
  `\persist in delusion, however satisfying and reassuring.” —Carl |
_o__)        Sagan |
Ben Finney

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


Re: Don't feed the troll...

2013-06-15 Thread Ben Finney
Cameron Simpson  writes:

> On 15Jun2013 10:42, Ben Finney  wrote:
> | The message sent to the individual typically arrives earlier (since
> | it is sent straight from you to the individual), and the message on
> | the forum arrives later (since it typically requires more
> | processing).
> | 
> | But since we're participating in the discussion on the forum and not
> | in individual email, it is the later one we want, and the earlier
> | one should be deleted.
>
> They're the same message! (Delivered twice.) Replying to either is
> equivalent.

Wrong. They have the same Message-Id, but one of them is delivered via
the mailing list, and has the correct RFC 3696 fields in the header to
continue the discussion there.

The one delivered individually is the one to discard, since it was not
delivered via the mailing list.

> Bah. Plenty of us like both. In the inbox alerts me that someone
> replied to _my_ post, and in the python mail gets it nicely threaded.

Your mail client doesn't alert you to a message addressed to you?

> Sorry, I could have sworn you said you weren't using a mail client for
> this...

As I already said, this is demonstrating the fact that “reply to all” is
broken even for the use case of participating via email.

-- 
 \  “Software patents provide one more means of controlling access |
  `\  to information. They are the tool of choice for the internet |
_o__)         highwayman.” —Anthony Taylor |
Ben Finney

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


Re: Don't feed the troll...

2013-06-18 Thread Ben Finney
Oscar Benjamin  writes:

> There is a very simple solution used by many mailing lists

Yes, that solution is described in RFC 2369: the “List-Post” field in
the header of every message sent through the mailing list.

> which is to set the Reply-To header to point back to the mailing list.

That is not a solution, since the ‘Reply-To’ field already has a
different purpose contrary to your intent. It is to be set by the person
sending the message, if they choose. It is not for some intermediary to
interfere with.

It is a field for the sender to direct *individual* responses back to
themselves – and, if they don't set that field, no intermediary should
abuse it.

> That way any old email client on any OS/computer/phone/website etc.
> has the required button to reply to the list without CCing anyone.

By breaking the standard “reply to author” behaviour. This is not a
solution.

The “List-Post” field has been standard for more than a decade. If
anyone is using an MUA that doesn't use it, please imrpove that
situation: pressure your vendor to fix that deficiency, and/or switch to
a better mail client until then.

> It also reduces the chance of accidentally replying off-list.

What damage is done by accidentally replying off-list? At worst, you
merely need to send the message again to the list. The damage is
minimal, and easily rectified.

Your proposed interference with the “Reply-To” field, though, invites
much more serious errors: it sets up a person to send a message to
people they did *not* intend, when using a function (“reply to author”,
often simply called “reply”) specifically for reaching the sender
*only*.

If your message contains information only intended to be seen by the
author to whom they are replying, the standard behaviour for “Reply-To”
gives the reasonable expectation it will go only to the author. But if a
broken mailing list that munges “Reply-To” to direct your reply to the
whole mailing list, that is damage which can't be un-done.

Please don't propose breaking standard behaviour by interfering with the
meaning of standard fields.

We have exactly the fields we need already: the RFC 2369 fields are in
the header of every message from the mailing list. The “List-Post”
field, saying where mail should be directed to reach the mailing list,
is exactly what is needed.

-- 
 \ “Ours is a world where people don't know what they want and are |
  `\   willing to go through hell to get it.” —Donald Robert Perry |
_o__)      Marquis |
Ben Finney

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


Re: how can I check if group member exist ?

2013-06-21 Thread Ben Finney
Hans  writes:

> I'm doing a regular expression matching, let's say
> "a=re.search(re_str,match_str)", if matching, I don't know how many
> str/item will be extracted from re_str

Can you show an example of the pattern, and several examples of text you
want to match? This will help to understand your issue.

Also, your terminology is using some confusing names. Try:

match = re.search(pattern, text)

That will use names which make it easier to think about the code.

-- 
 \ “Ours is a world where people don't know what they want and are |
  `\   willing to go through hell to get it.” —Donald Robert Perry |
_o__)          Marquis |
Ben Finney

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


Re: n00b question on spacing

2013-06-22 Thread Ben Finney
"Yves S. Garret"  writes:

> I have the following line of code:
> log.msg("Item wrote to MongoDB database %s/%s" %(settings['MONGODB_DB'],
> settings['MONGODB_COLLECTION']), level=log.DEBUG, spider=spider)
[…]

> Is this ok? Are there any rules in Python when it comes to breaking up
> long lines of code?

PEP 8 is the common denominator; follow its restrictions and your code
will be a lot more readable to just about any Python programmer. So,
indent 4 columns for block structure, preferably 8 columns for
continuation lines, put spaces around binary operators, etc.

As for *where* to break long lines: I prefer the continuation lines to
be a standard indentation (4 or 8 columns), which means the indentation
doesn't need to change when the first line changes later. So I break at
an open paren, brace, bracket (‘(’, ‘{’, ‘[’) etc. and allow Python to
automatically continue the statement until that bracketing is closed.

log.msg(
"Item wrote to MongoDB database %s/%s"
% (settings['MONGODB_DB'], settings['MONGODB_COLLECTION']),
level=log.DEBUG, spider=spider)

That way, if the first line changes later, you don't need to change any
of the indentation on the continuation lines:

logger.info(
"Item wrote to MongoDB database %s/%s"
% (settings['MONGODB_DB'], settings['MONGODB_COLLECTION']),
level=log.DEBUG, spider=spider)

-- 
 \ “[W]e are still the first generation of users, and for all that |
  `\  we may have invented the net, we still don't really get it.” |
_o__)   —Douglas Adams |
Ben Finney

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


Re: Python development tools

2013-06-23 Thread Ben Finney
rusi  writes:

> I dont know what you mean my 'scripting'

Any time someone has shown me a “Python script”, I don't see how it's
different from what I'd call a “Python program”. So I just mentally
replace “scripting with “programming”.

-- 
 \  “Dvorak users of the world flgkd!” —Kirsten Chevalier, |
  `\rec.humor.oracle.d |
_o__)      |
Ben Finney

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


Re: Python development tools

2013-06-24 Thread Ben Finney
rusi  writes:

> On Monday, June 24, 2013 11:50:38 AM UTC+5:30, Ben Finney wrote:
> > Any time someone has shown me a “Python script”, I don't see how
> > it's different from what I'd call a “Python program”. So I just
> > mentally replace “scripting with “programming”.
>
> If you are saying that python spans the scripting to programming
> spectrum exceptionally well, I agree. 

I'm saying that “scripting” is a complete subset of “programming”, so
it's nonsense to talk about “the scripting-to-programming spectrum”.

Scripting is, always, programming. Scripts are, always, programs. (But
not vice-versa; I do acknowledge there is more to programming than
scripting.) I say this because anything anyone has said to me about the
former is always something included already by the latter.

So I don't see much need for treating scripts as somehow distinct from
programs, or scripting as somehow distinct from programming. Whenever
you're doing the former, you're doing the latter by definition.

> I dont however think that the two philosophies are the same. See
> http://www.tcl.tk/doc/scripting.html

That essay constrasts “scripting” versus “system programming”, a useful
(though terminologically confusing) distinction.

It's a mistake to think that essay contrasts “scripting“ versus
“programming”. But the essay never justifies its aversion to
“programming” as a term for what it's describing, so that mistake is
easy to make.

-- 
 \   “A celebrity is one who is known by many people he is glad he |
  `\  doesn't know.” —Henry L. Mencken |
_o__)  |
Ben Finney

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


Re: (newbye) exceptions list for python3 classes

2013-06-24 Thread Ben Finney
chrem  writes:

> Hi,

Howdy, congratulations on finding the Python programming language.

> what is the best way to find out all exceptions for a class?

Python is not Java. Your program doesn't need to know everything that
might happen; you should catch only those exceptions you can actually
deal with usefully, and let any others propagate.

> E.g. I want to find out all exceptions related to the zipfile (I'm
> searching for the Bad password exception syntax).

The documentation will describe the behaviour of the module; many
exceptions are implied by that (e.g. if the module deals with the
filesystem, you can expect OSError to be raised under certain
conditions).

Other exceptions will come from deeper within Python; e.g. if you give
text in a bad encoding you can expect UnicodeDecodeError, or if you give
it an object that can't be handled as expected you might get a TypeError.

But trying to get a complete set of all exceptions that might be raised
is a fool's errand. It would be futile, both because everything in
Python is an object and can therefore raise whatever exceptions are
appropriate, and also because even if you knew a complete set, you can't
usefully do anything consistent with such a huge set of exception types.

So, what is it you want to do one you know a set of exception types that
can be raised by the code?

> thanks for your help or feedback,

Hope that helps, and good fortune to you in learning to code Pythonically!

-- 
 \  “When we talk to God, we're praying. When God talks to us, |
  `\ we're schizophrenic.” —Jane Wagner, via Lily Tomlin, 1985 |
_o__)          |
Ben Finney

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


Re: FACTS: WHY THE PYTHON LANGUAGE FAILS.

2013-06-26 Thread Ben Finney
Thrinaxodon  writes:

> [… strange fictitious dialogue …]
> THRINAXODON IS NOW ON TWITTER.

Thrinaxodon should not bother to post such hostility here again.

-- 
 \  “I don't want to live peacefully with difficult realities, and |
  `\ I see no virtue in savoring excuses for avoiding a search for |
_o__)real answers.” —Paul Z. Myers, 2009-09-12 |
Ben Finney

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


Re: python adds an extra half space when reading from a string or list

2013-07-02 Thread Ben Finney
Joshua Landau  writes:

> On 2 July 2013 13:01, Antoon Pardon  wrote:
> > Please answer the following question. If someone behaved
> > incompetently, how can I clearly state that fact when
> > "incompetently" is seen as an insult and insults don't belong on the
> > list?
>
> There is not ever a place on this list where you will need to call
> someone incompetent.

So even if that term describes their behaviour and manner, you think
no-one should ever point it out?

> > So what are the non-insulting terms for
> >
> > incompentent, (starting a webservice in a language you're a newby in,
> > making changes on the life server so that any typo you make, can take
> > your site out the air),
>
> You just did it.

So you agree the correct term to use *is* “incompetent”, as Anton said.
Yet you don't want Anton to use the correct term.

Needless to say, I disagree with your position. There is no place for
baseless insults in this community; but when the behaviour of someone in
this community is harmful, then it is entirely appropriate to use clear
terms (e.g. “incompetent”, “inconsiderate”) to describe their behaviour.

-- 
 \  “One bad programmer can easily create two new jobs a year. |
  `\  Hiring more bad programmers will just increase our perceived |
_o__) need for them.” —David Lorge Parnas, 1999-03 |
Ben Finney

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


Re: Python list code of conduct

2013-07-02 Thread Ben Finney
Steve Simmons  writes:

> It probably isn't the best time to start this post but I was
> wondering...

An excellent time to raise this, in my opinion. Thank you for doing so.

> Does this list have a code of conduct or a netiqeutte (sp?)
> statement/requirement? 

This forum (both a Usenet newsgroup and a mailing list) is part of the
Python community. So the “Python Community Code of Conduct” applies.

http://www.python.org/psf/codeofconduct/>

That was formed by the Python community and adopted by our gracious
hosts, the Python Software Foundation, who provide this forum for our
use.

> The reason I ask is that it seems to me that if we (the current
> membership of the list) could agree to a set of preferred/required
> behaviours we would at least have a framework by which to measure
> unwelcome posts.

I welcome use of the above code of conduct to guide social norms in this
community.

> And, more importantly, to guide newcomers in understanding that we are
> enthusiasts who choose to discuss Python and *voluntarily* help solve
> problems with Python for the less experienced members.

Amen.

-- 
 \  “If sharing a thing in no way diminishes it, it is not rightly |
  `\  owned if it is not shared.” —Saint Augustine |
_o__)          |
Ben Finney

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


Re: python adds an extra half space when reading from a string or list

2013-07-02 Thread Ben Finney
Joshua Landau  writes:

> Firstly, describing someone's behaviour and describing someone's
> character are two completely different things.

I agree with that.

> Antoon is describing people's character.

I disagree with that. To merely describe someone as “incompetent” is not
to describe their behaviour: they are not competent to do what they are
attempting, which is not a judgement on their character. Just as to
merely describe someone as “ignorant” is to describe their lack of
knowledge in some area, and is not a judgement on their character.

Even character judgements can be appropriate, so long as they are
salient to the acceptable behaviours in this forum; there are many
character attributes that are incompatible with this community.

So since both accurate description of actions and character judgement
can be appropriate for discussing acceptable behaviour here, I'll thank
you not to make absolute prohibitions against either.

> You are talking about describing their actions.

Yes.

Since you seem to be imputing character judgements to descriptions which
are accurate descriptions of behaviour, I think we've found the root of
the disagreement. I've made my position clear and will let it rest there.

> Calling someone incompetent is an attack

It can be part of an attack, but in itself is merely a description of
someone's behaviour.

> If you cannot see the difference, I'm not sure what more I can say.

Likewise. Thanks for caring enough about this community to act in the
interest of keeping it open, considerate, and respectful.

-- 
 \ “Beware of and eschew pompous prolixity.” —Charles A. Beardsley |
  `\   |
_o__)          |
Ben Finney

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


Re: Python list code of conduct

2013-07-02 Thread Ben Finney
Dennis Lee Bieber  writes:

> So who would enforce any rules?

Ideally, this community is healthy enough for us to enforce the code of
conduct of our host, through social convention among us all.

-- 
 \“I took a course in speed waiting. Now I can wait an hour in |
  `\ only ten minutes.” —Steven Wright |
_o__)  |
Ben Finney

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


Re: python adds an extra half space when reading from a string or list

2013-07-03 Thread Ben Finney
rusi  writes:

> As a good Christian I believe that Chris tried more than anyone else
> on this list to help Nikos before talking recourse to another gem of
> biblical wisdom:

> He that spareth his rod hateth his son: but he that loveth him
> chasteneth him betimes.

Good Christian morality entails biblical encouragement to beat one's
child with a rod, I see.

Please, may I be spared encounters with good Christians.

Let's end right now the insidious doctrine that beating a person –
metaphorically or otherwise – is ever acceptable in this forum. If that
contradicts anyone's good Christian morality, then good Christian
morality is dead wrong and needs to be rejected.

-- 
 \ “Wrinkles should merely indicate where smiles have been.” —Mark |
  `\Twain, _Following the Equator_ |
_o__)          |
Ben Finney

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


Re: [SPOILERS] Python easter eggs

2013-07-03 Thread Ben Finney
Ian Kelly  writes:

> from __future__ import barry_as_FLUFL

Only works in Python 3 (raises a SyntaxError in Python 2).

> import __hello__

Different between Python 2 and Python 3 — try it in both!

-- 
 \  “I spent all my money on a FAX machine. Now I can only FAX |
  `\  collect.” —Steven Wright |
_o__)      |
Ben Finney

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


IPv6 deployment by ISPs (was: Bug reports)

2013-07-03 Thread Ben Finney
Chris Angelico  writes:

> Yeah, and yet so many ISPs simply don't support it [IPv6] (only one of
> the Australian ISPs I've worked with does - Internode).

Internode was the first in Australia, yes. Telstra supports IPv6, but
only for enterprise/government customers.

Wikipedia has a list of IPv6 deployment status by country
https://en.wikipedia.org/wiki/IPv6_deployment#Deployment_by_country>.

-- 
 \ “How wonderful that we have met with a paradox. Now we have |
  `\some hope of making progress.” —Niels Bohr |
_o__)          |
Ben Finney

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


Re: Documenting builtin methods

2013-07-10 Thread Ben Finney
Joshua Landau  writes:

> I have this innocent and simple code:
>
> from collections import deque
> exhaust_iter = deque(maxlen=0).extend
> exhaust_iter.__doc__ = "Exhaust an iterator efficiently without
> caching any of its yielded values."
>
> Obviously it does not work.

Right. It raises a SyntaxError because you've got a simple string
literal that isn't closed before the end of the line.

> Is there a way to get it to work simply

What behaviour would you expect from that? We can't guess what you mean
by “get it to work” unless we know what you're expecting and how the
observed behaviour is different.

A good way to do this would be to show some actual code that
demonstrates the surprising behaviour (you may need to post using a
service that doesn't munge your text), along with the traceback if any.

Then, show a session that behaves the way you'd expect it to behave, and
we can explain either how to achieve that or why it can't.

-- 
 \ Q: “I've heard that Linux causes cancer...” Torvalds: “That's a |
  `\ filthy lie. Besides, it was only in rats and has not been |
_o__)   reproduced in humans.” —Linus Torvalds |
Ben Finney

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


Re: Documenting builtin methods

2013-07-11 Thread Ben Finney
Joshua Landau  writes:

> On 11 July 2013 05:13, Joshua Landau  wrote:
> > 
>
> Ah, I get it. It is easy to misread my post as "I have this
> exhaust_iter" and it's obvious it doesn't work because why else would
> I post here what do I do HALP!

Right. Just because you think there's one obvious interpretation of your
cry for help, doesn't mean there's *only* one obvious interpretation.

It's best to be explicit: describe what behaviour you're seeing, and
what behaviour you're expecting to see.

-- 
 \   “We must respect the other fellow's religion, but only in the |
  `\   sense and to the extent that we respect his theory that his |
_o__)     wife is beautiful and his children smart.” —Henry L. Mencken |
Ben Finney

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


Re: Python testing tools

2013-07-20 Thread Ben Finney
cutems93  writes:

> I am currently doing some research on testing software for Python. I
> found that there are many different types of testing tools. These are
> what I've found.

You will find these discussed at the Python Testing Tools Taxonomy
http://wiki.python.org/moin/PythonTestingToolsTaxonomy>.

Hope that helps.

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


Re: could you change PYPI downloads number for not-uploaded packages?

2013-07-22 Thread Ben Finney
Robert Kern  writes:

> On 2013-07-22 16:44, dmitre...@gmail.com wrote:

> > For example, my projects download links are binded to my website ,
> > and thus people see misleading zeros […]

> In short, if you want to have download counts, you will need to host
> your package downloads from PyPI itself.

Also of interest to this group is that PyPI is transitioning to strongly
encourage hosting files at PyPI, and installer tools will default to not
installing files hosted elsewhere.

See PEP 438 “Transitioning to release-file hosting on PyPI”
http://www.python.org/dev/peps/pep-0438/> for the details. As
Robart said, it's best not discussed here, but at the ‘distutils-sig’
forum http://www.python.org/community/sigs/current/distutils-sig/>.

-- 
 \   “I do not believe in immortality of the individual, and I |
  `\consider ethics to be an exclusively human concern with no |
_o__)  superhuman authority behind it.” —Albert Einstein, letter, 1953 |
Ben Finney

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


Re: How to read a make file in python and access its elements

2013-07-22 Thread Ben Finney
san  writes:

> I have a scenario, where i need to load the make file and access its
> elements.  

What do you mean by “elements” of a make file? Is that a term with a
specific meaning, or do you mean some particular parts of the make file?

> I have tried reading the make file as text file and parsing it,but its
> not the ideal solution 

You might be interested in using a library purpose-built for creating a
parser http://pyparsing.wikispaces.com/>.

I'm not aware of any makefile-syntax-aware tool for Python. Your best
option could be to write your own parser using the above library.

-- 
 \ “True greatness is measured by how much freedom you give to |
  `\  others, not by how much you can coerce others to do what you |
_o__)   want.” —Larry Wall |
Ben Finney

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


Re: Python testing tools

2013-07-23 Thread Ben Finney
cutems93  writes:

> On Saturday, July 20, 2013 1:11:12 AM UTC-7, Ben Finney wrote:
> > You will find these discussed at the Python Testing Tools Taxonomy
> > http://wiki.python.org/moin/PythonTestingToolsTaxonomy>.
> > 
> > Hope that helps.
>
> Thank you, but I already read this page before I posted this question.

(You will benefit from also reading and applying
http://wiki.python.org/moin/GoogleGroupsPython> before using Google
Groups. My advice: choose a different interface to this forum, Google
Groups is terrible.)

> What I want to know is whether you personally use these tools other
> than unit testing tools.

Yes, I do :-)

What are you actually wanting to learn, beyond a collection of “this is
what I use” stories?

-- 
 \  “The way to build large Python applications is to componentize |
  `\ and loosely-couple the hell out of everything.” —Aahz |
_o__)          |
Ben Finney

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


Re: Python 3: dict & dict.keys()

2013-07-24 Thread Ben Finney
Ethan Furman  writes:

> On 07/23/2013 07:11 PM, Steven D'Aprano wrote:
> > On Tue, 23 Jul 2013 18:16:08 -0700, Ethan Furman wrote:
> >> And everything I thought I knew about when to use one or the other went
> >> out the window.
> >
> > Surely not. The fundamental behaviour of Python's data model hasn't
> > changed.
>
> Poetic effect.  Dramatic license.  Blah blah.  ;)

Text-only medium. Clarity of communication. Et cetera. :-)

-- 
 \   “Two hands working can do more than a thousand clasped in |
  `\   prayer.” —Anonymous |
_o__)          |
Ben Finney

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


Re: Hello Everyone! A simple questions!

2013-07-25 Thread Ben Finney
Thanatos xiao  writes:

> >>> values = [0, 1, 2]>>> values[1] = values>>> values[0, [...], 2]
>
> why??

Because. :-)

Did you have a more specific question? What exactly are you expecting
that code to do, and what is the surprise?

-- 
 \  “I was the kid next door's imaginary friend.” —Emo Philips |
  `\   |
_o__)          |
Ben Finney

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


Re: Python Script Hashplings

2013-07-26 Thread Ben Finney
Tim Golden  writes:

> Devyn, I'm not a *nix person so someone can point out if I'm wrong,
> but my understanding is that the shebang line (or whatever you want to
> call it) just tells the shell: run this command to run this file. So
> you can put "#!/usr/bin/fish-and-chips" as the first line and it will
> try to run the file using /usr/bin/fish-and-chips.

Close: it's an instruction not to the shell, but to the kernel. The
shell defers any “run the program in this file” to the kernel, and it's
the kernel that pays attention to the file's shebang line.

-- 
 \  “When cryptography is outlawed, bayl bhgynjf jvyy unir |
  `\  cevinpl.” —Anonymous |
_o__)          |
Ben Finney

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


Re: How can i call array_length to get the length of array object?

2012-06-24 Thread Ben Finney
Mark Lawrence  writes:

> On 24/06/2012 09:15, gmspro wrote:
>
> > Why __len__() where the original name if array_length? Why is method
> > names like __NAME__ ?

These are questions answered by getting a thorough grounding in the
fundamentals of Python. Please follow the Python tutorial
http://docs.python.org/tutorial/>, from beginning to end, to learn
about the basics like this.

> Why are you too bloody lazy to do any research before you post
> questions?

I understand your frustration in this case, but there's no call for such
vitriol. Please keep it off this forum.

-- 
 \“Pinky, are you pondering what I'm pondering?” “Wuh, I think |
  `\   so, Brain, but wouldn't anything lose its flavor on the bedpost |
_o__)       overnight?” —_Pinky and The Brain_ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Seeking Python Programmer - San Jose, CA

2012-06-28 Thread Ben Finney
Flexton Inc  writes:

> Do you love coding and Interested in exploring Python? OR Expert in
> Python, we have a requirement on Contract to Hire position
[…]

Please do not use this forum for recruiting. Instead, use the Python
Job Board http://www.python.org/community/jobs/> for that purpose.

-- 
 \ “There is something wonderful in seeing a wrong-headed majority |
  `\   assailed by truth.” —John Kenneth Galbraith, 1989-07-28 |
_o__)          |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I can't send images to this mail-list

2012-06-29 Thread Ben Finney
Chris Angelico  writes:

> On Thu, Jun 28, 2012 at 9:34 PM, 梦幻草  wrote:
> >     why can't I send images to python-list@python.org??
>
> It's a text-only list.

I'll take this opportunity to give heartfelt thanks to the
administrators for that policy; please keep this a text-only forum.

-- 
 \   “Come on Milhouse, there’s no such thing as a soul! It’s just |
  `\  something they made up to scare kids, like the Boogie Man or |
_o__)  Michael Jackson.” —Bart, _The Simpsons_ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re Following syntax error in Mac OX10.7 Terminal

2012-06-29 Thread Ben Finney
David Thomas  writes:

> Hi yeah I'm currently learning python 2 at the moment and the tutorial
> that I am studying doesn't explain about indentation.

You might be better served by the official Python tutorial
http://docs.python.org/tutorial/>.

If you work through it from beginning to end, doing each exercise and
experimenting to be sure you understand before moving through, you will
get a good grounding in the fundamentals of the language.

-- 
 \   “Don't worry about what anybody else is going to do. The best |
  `\ way to predict the future is to invent it.” —Alan Kay |
_o__)      |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: code review

2012-06-30 Thread Ben Finney
Thomas Jollans  writes:

> My sole point, really, is that "normally", one would expect these two
> expressions to be equivalent:
>
> a < b < c
> (a < b) < c

What norm gives you that expectation? That's not how those operators
work in mathematical notation. I know of no programming language that
would give a newcomer to Python that expectation. So where is the norm
you're referring to?

The operator symbols are not chosen arbitrarily for Python; they are, in
the case of ‘<’ and ‘>’, chosen because of semantic meaning those
symbols already have. That's the norm informing this meaning, and I
think it negates the point you're making.

> This is clearly not true. That's the inconsistency here with the rest
> of the language.

There is inconsistency already in the symbols people see and the
semantics already associated with those symbols. Expecting that any
symbol, before Python defines it, will be devoid of any normal meaning
is a delusion.

-- 
 \ “The Vatican is not a state.… a state must have territory. This |
  `\ is a palace with gardens, about as big as an average golf |
_o__) course.” —Geoffrey Robertson, 2010-09-18 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: code review

2012-07-01 Thread Ben Finney
Chris Angelico  writes:

> On Sun, Jul 1, 2012 at 10:08 AM, Ben Finney  
> wrote:
> > Thomas Jollans  writes:
> >
> >> My sole point, really, is that "normally", one would expect these two
> >> expressions to be equivalent:
> >>
> >> a < b < c
> >> (a < b) < c
> >
> > What norm gives you that expectation? That's not how those operators
> > work in mathematical notation. I know of no programming language
> > that would give a newcomer to Python that expectation. So where is
> > the norm you're referring to?
>
> C, SQL, REXX, and many other languages.

So, languages without strong typing then. In that case, I revise my
statement: I know of no programming language with strong typing that
would give a newcomer to Python the above expectation.

Since Python does have strong typing, norms about operations from
weakly-typed languages should not be expected to apply.

(Incidentally, PostgreSQL was the SQL implementation I went to, and::

postgres=# SELECT (1 < 2) < 3;
ERROR:  operator does not exist: boolean < integer
LINE 1: SELECT (1 < 2) < 3;
   ^
HINT:  No operator matches the given name and argument type(s). You might 
need to add explicit type casts.

So not all SQL implementations make the mistake of weak typing.)

-- 
 \ “Try adding “as long as you don't breach the terms of service – |
  `\  according to our sole judgement” to the end of any cloud |
_o__)  computing pitch.” —Simon Phipps, 2010-12-11 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: code review

2012-07-02 Thread Ben Finney
rusi  writes:

> Similar for standardized languages: Python's indentation is nice --
> except when you have to embed it into say, html

If you can't write a ‘pre’ element for pre-formatted text, you don't
have HTML http://www.w3.org/TR/html401/struct/text.html#h-9.3.4>.

-- 
 \ “Pinky, are you pondering what I'm pondering?” “Uh, I think so, |
  `\ Brain, but we'll never get a monkey to use dental floss.” |
_o__)       —_Pinky and The Brain_ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: code review

2012-07-16 Thread Ben Finney
Duncan Booth  writes:

> Technically of course Python doesn't have assignment, it just binds
> names.

Names, or other references.

I'd argue that Python has assignment, and assignment in Python is
identical with binding references to objects.

But then, the Python documentation refers to “variables” as though they
exist in Python, which I'd argue they don't. It's all very confusing :-)

-- 
 \ “Religious faith is the one species of human ignorance that |
  `\ will not admit of even the *possibility* of correction.” —Sam |
_o__) Harris, _The End of Faith_, 2004 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Initial nose experience

2012-07-16 Thread Ben Finney
Roy Smith  writes:

> In article ,
>  pyt...@bdurham.com wrote:
>
> > After years of using unittest, what would you say are the pros and
> > cons of nose?
>
> BTW, although I'm currently using nose just as a unittest aggregator

Be aware that Python 2.7 and higher has unit test discovery in the
standard library:

$ python -m unittest discover

will look through all packages within the current directory and collect
unit tests it finds, then run them and report
http://docs.python.org/library/unittest.html#test-discovery>.

You can get the same in earlier versions of Python with ‘unittest2’
http://pypi.python.org/pypi/unittest2>.

-- 
 \   “I prayed for twenty years but received no answer until I |
  `\  prayed with my legs.” —Frederick Douglass, escaped slave |
_o__)          |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Google the video blah blah jews blah blah 9/11 blah blah conspiracy blah cia blah blah blah zionist blah blah brainwashing blah blah blah

2012-07-20 Thread Ben Finney
Steven D'Aprano  writes:

> On Thu, 19 Jul 2012 10:27:02 -0400, Matty Sarro wrote:
>
> > I must be a Jew or a traitor as I keep deleting this email.
>
> You might be both.

https://www.youtube.com/watch?v=7kYVaycn5Fc>

-- 
 \   “My business is to teach my aspirations to conform themselves |
  `\  to fact, not to try and make facts harmonise with my |
_o__)   aspirations.“ —Thomas Henry Huxley, 1860-09-23 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the meaning of rユ.......ï¾

2012-07-24 Thread Ben Finney
Chris Angelico  writes:

> […] Pi Day, has two different dates (the American and the European -
> of course, here in Australia, we celebrate both).

What would be the two days? The 14th day of the 3rd month, and, um,
what?

Or do you Australians have the third day of the fourteenth month?

-- 
 \  “Earth gets its price for what Earth gives us.” —James Russell |
  `\Lowell |
_o__)      |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the meaning of rユ.......ï¾

2012-07-24 Thread Ben Finney
Maarten  writes:

> You just missed it:
> 22/7

Which is appropriate, since 22/7 misses π by a wide margin. (355/113 is
my favourite approximation to π, and is far more accurate.)

−1 on associating 22/7 as anything to do with π.

+1 on celebrating τ day! https://www.youtube.com/watch?v=jG7vhMMXagQ>

-- 
 \ “Why am I an atheist? I ask you: Why is anybody not an atheist? |
  `\  Everyone starts out being an atheist.” —Andy Rooney, _Boston |
_o__)Globe_ 1982-05-30 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the meaning of rユ.......ï¾

2012-07-24 Thread Ben Finney
Mark Lawrence  writes:

> Any civil engineers reading this who would find 22/7 perfectly
> adequate for their task?

Civil engineering? Pffft, that deals with only a few orders of magnitude
range at most. “π is roughly 3” is usually good enough in that arena :-)

-- 
 \ “You don't need a book of any description to help you have some |
  `\kind of moral awareness.” —Dr. Francesca Stavrakoloulou, bible |
_o__)  scholar, 2011-05-08 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Text editors

2012-07-28 Thread Ben Finney
Tim Chase  writes:

> On Sat, Jul 28, 2012 at 6:29 PM, Mark Lawrence wrote:
> > I highly recommend the use of notepad++.  If anyone knows of a
> > better text editor for Windows please let me know :)

I highly recommend not tying your editor skills to a single OS,
especially one as ornery for programmers as Windows.

> I'll advocate for Vim which is crazy-powerful and works nicely on
> just about any platform I touch.
>
> Others will advocate for Emacs, which I can't say fits the way my
> brain works but it's also powerful and loved by many.

Right. I'm in Tim's position, but reversed: my preference is for Emacs
but Vim is a fine choice also. They are mature, well-supported with
regular updates and a massive library of plug-ins for different uses,
have a huge community to help you, and work on all major programming
OSen.

> The ubiquity of these two platforms makes a worthwhile investment of
> time spent in learning at least one if not both.

I use both frequently in my work for different things, and they are good
for pretty much any task involving manipulation of text.

Learn one of Emacs or Vim well, and you won't need to worry about text
editors again.

-- 
 \“All opinions are not equal. Some are a very great deal more |
  `\   robust, sophisticated, and well supported in logic and argument |
_o__)         than others.” —Douglas Adams |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Text editors

2012-07-29 Thread Ben Finney
rusi  writes:

> Do you use the emacs builtin python mode or the separate python-mode?

I'm not sure. I have both installed.

I try to keep my Emacs setup portable across different machines, so I'm
probably using the built-in mode.

> Do you use pdb?

Occasionally, but I haven't learned how to do that in Emacs.

> Any other special setups?

GNU Screen and Emacs are the foundation of my programming environment.

> How about ipython?

Never really liked it nor saw a need for it. I use the Python
interactive console, with GNU readline so I get history preserved and
tab-completion.

> But I am getting increasing 'funny looks' for not (for example) using
> eclipse.]

Unless those funny looks are accompanied by compelling reasons to invest
a whole lot of effort into learning a rather slow and complex program,
then it seems you can ignore them.

-- 
 \  “The way to build large Python applications is to componentize |
  `\ and loosely-couple the hell out of everything.” —Aahz |
_o__)          |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyPI question, or, maybe I'm just stupid

2012-07-29 Thread Ben Finney
Chris Gonnerman  writes:

> I've been making some minor updates to the PollyReports module

Your post is showing up as a reply to a thread about IEEE-784 floats,
because you created your message as a reply. Consequently, it's rather
confusing why you suddenly start talking about PollyReports.

If you want to attract attention to an unrelated topic, it's best if you
don't reply to an existing thread; instead, start a new thread by
composing a new message to the forum.

-- 
 \“I'd take the awe of understanding over the awe of ignorance |
  `\  any day.” —Douglas Adams |
_o__)      |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: On-topic: alternate Python implementations

2012-08-05 Thread Ben Finney
Mark Lawrence  writes:

> With arrogance like that German by any chance?

Please keep derogatory national stereotypes off this forum and out of
our community. They are counter to our goals of diversity
http://www.python.org/community/diversity/>; you don't have to
subscribe to that, but if not then you thereby exclude yourself.

-- 
 \   “You can stand tall without standing on someone. You can be a |
  `\ victor without having victims.” —Harriet Woods, 1927–2007 |
_o__)      |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a good introduction to object oriented programming with Python

2012-08-06 Thread Ben Finney
Steven D'Aprano  writes:

> Please trim unnecessary quoted text. 
>
> We don't need to see the entire thread of comment/reply/reply-to-reply 
> duplicated in *every* email.

s/every/any/

-- 
 \   “If you make people think they're thinking, they'll love you; |
  `\ but if you really make them think, they'll hate you.” —Donald |
_o__)         Robert Perry Marquis |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Looking for a good introduction to object oriented programming with Python

2012-08-07 Thread Ben Finney
lipska the kat  writes:

> >>>> The ONLY concept that you should never try to encapsulate is/are
> >>>> human beings or their aliases.

You stated this in absolute, dogmatic terms. I thought at first you were
being hyperbolic for effect, but the situation that you present to
support this dogma is one where I can't see anyone rationally concluding
the dogma applies.

> Well now this is a personal thing born of bitter experience. In my
> experience, when you have an entity called 'Person' or some such in
> your Class model it soon becomes what we 'in the trade' call a 'God
> Object' The name should be self explanatory but hold tight, here comes
> some more jargon.

God objects are a code smell (another term of art, meaning a symptom in
the code that tends to indicate poor design or some other fundamental
flaw). But what you're describing below doesn't fit.

> Objects can have a 'has a' relationship with other Objects or an 'is a'
> relationship with other objects
>
> The 'has a' relationship means that an Object 'owns' another object,
> the is a' relationship means that an Object 'is of a particular type'
> Of course in an 'Object Oriented' language such as Java an Object
> reference can have a different type at runtime than it does at compile
> time. In Python too.
>
> Anyway, this Person thing soon ends up with a 'has a' relationship
> with everything in sight. a Person 'has a[n]' Address, a Person 'has
> a[n]' account, a Person 'has a' Doughnut etc etc etc
>
> Also, inevitably a Person 'is a' Customer, a Person 'is a' Contact, a
> Person 'is a' security risk, well you get the idea.

This accurately reflects the reality that “person” is a real-world
entity very frequently involved in just about anything a typical system
needs to model.

> Of course this is a problem with the actual design process itself

What problem? If the real-world entity really exists and the “has-a” and
“is-a” relationships really exist, then it's *good* design to model
whatever ones of those are significant to the operation of the program.

Indeed, it would be *bad* design to avoid modelling the real world
merely because of dogma against modelling persons and their
relationships to other entities.

If there were entities or relationships that were needlessly cumbersome
– if indeed the object was trying to encapsulate the majority of the
whole world in itself – then those should be removed from the object,
and perhaps even from the design.

But that's not what you describe. A Person entity in inheritance or
composition relationships with other classes and objects is not a god
object, since it is sensibly delegating specific jobs to places other
than itself. That's very good, modular design.

And when the real domain to be modelled almost certainly has people as a
central entity in complex interactions, removing Person from the design
entirely is poor work grounded in irrationality.

-- 
 \   “I am amazed, O Wall, that you have not collapsed and fallen, |
  `\since you must bear the tedious stupidities of so many |
_o__)  scrawlers.” —anonymous graffiti, Pompeii, 79 CE |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I thought I understood how import worked...

2012-08-07 Thread Ben Finney
Roy Smith  writes:

> So, it appears that you *can* import a module twice, if you refer to
> it by different names! This is surprising.

The tutorial is misleading on this. It it says plainly:

A module can contain executable statements as well as function
definitions. […] They are executed only the *first* time the module
is imported somewhere.

http://docs.python.org/tutorial/modules.html>

but it doesn't make clear that a module can exist in the ‘sys.modules’
list multiple times under different names.

Care to file a documentation bug http://bugs.python.org/>
describing this?

> It means that having non-idempotent code which is executed at import
> time is a Bad Thing.

This is true whether or not the above about module imports is true. A
well-designed module should have top level code that performs idempotent
actions.

Be thankful that you've discovered this, and apply it well :-)

-- 
 \   “See, in my line of work you gotta keep repeating things over |
  `\   and over and over again, for the truth to sink in; to kinda |
_o__)   catapult the propaganda.” —George W. Bush, 2005-05 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I thought I understood how import worked...

2012-08-07 Thread Ben Finney
Cameron Simpson  writes:

> All of you are saying "two names for the same module", and variations
> thereof. And that is why the doco confuses.
>
> I would expect less confusion if the above example were described as
> _two_ modules, with the same source code.

That's not true though, is it? It's the same module object with two
different references, I thought.

Also, even if what you say were true, “source code” implies the module
was loaded from source code, when Python allows loading modules with no
source code available. So that implication just seems to be inviting
different confusion.

-- 
 \ “I'm not a bad guy! I work hard, and I love my kids. So why |
  `\  should I spend half my Sunday hearing about how I'm going to |
_o__)            Hell?” —Homer Simpson |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Geneology Packages

2012-08-08 Thread Ben Finney
Simon Cropper  writes:

> Since we have graduated to a completely different topic I have renamed
> the thread.

Thank you.

> If people are interested in a totally python-based open source FREE
> (as in no $$) package that can do all the above try gramps...
>
> http://gramps-project.org/

In addition to being open source and zero-cost, more importantly it is
free software.

> I have used this package for a few years now and it is fantastic.

I'm glad to hear this; I have seen Gramps mentioned for many years and
it's great to see a mature (> 10 years) Python project that's still
going strong and meeting a specialised need with free software.

-- 
 \ “I object to doing things that computers can do.” —Olin Shivers |
  `\   |
_o__)          |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to uncompress a VOB file? (Win XP)

2012-08-13 Thread Ben Finney
Xantipius  writes:

> subj

resp

-- 
 \ “What is needed is not the will to believe but the will to find |
  `\   out, which is the exact opposite.” —Bertrand Russell, _Free |
_o__)   Thought and Official Propaganda_, 1928 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pylagiarism -- Need help now! Please provide code...

2012-08-14 Thread Ben Finney
Simon Cropper  writes:

> I just had a great idea for a new python module. I haven't bothered
> googling it or doing any research.

That's the perfect time: everyone knows that ideas and enthusiasm are
the key to a successful project. Show them early, and people will flock
to you.

Mind you, it's best if you show even *more* enthusiasm by telling us
that you've been searching all day. Don't waste your time with a better
description of what you're looking for, though.

> I need help putting together some code; today preferably, my boss is
> on my back. Can someone please contribute a functioning module showing
> me how to do it?

You have exactly the right approach. I'm sure this is just how you
learned to program in your tertiary school: ask who has already done
your work, without wasting time thinking about the problem.

> So, now you know where I am coming from, I would like to thank you for
> all your help. Remember though, I need help now, so please stop what
> you are doing and submit something quickly. I'm waiting...

How can this approach fail! I anticipate you will have a working program
interfrastically.

-- 
 \   “If you always want the latest and greatest, then you have to |
  `\  buy a new iPod at least once a year.” —Steve Jobs, MSNBC |
_o__)         interview 2006-05-25 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: EXTERNAL: Re: pylagiarism -- Need help now! Please provide code...

2012-08-14 Thread Ben Finney
Damon Register  writes:

> On 8/14/2012 5:32 AM, Simon Cropper wrote:
> > Anyone willing to contribute money to help with the compilation of
> > the code will get a portion of the profits. Just send me your
> > account details, name and address; and I will ensure, once I have
> > been paid, that I will send you your cut! :)
> You forgot about the part where you have leukemia and have only a
> month to live so you will leave all the profits to me.

Surely he is the heir of a member of the royal family? And all he needs
is 5% of the total amount deposited to open the account, after which the
full amount of the inheritance will be transferred.

-- 
 \ “I may disagree with what you say, but I will defend to the |
  `\death your right to mis-attribute this quote to Voltaire.” |
_o__)   —Avram Grumer, rec.arts.sf.written, 2000-05-30 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to uncompress a VOB file? (Win XP)

2012-08-14 Thread Ben Finney
Steven D'Aprano  writes:

> (However, I don't promise not to roll my eyes if they choose a silly 
> moniker, and I am the final arbitrator as to what counts as silly.)

I also don't promise to remember or comply with their request to be
known by an egregiously silly moniker, with me as the sole arbiter of
what counts as “egregiously silly”.

People have the right to ask to be known by a particular name, but they
are obliged to be reasonable about how successful their request will be
when they ask.

-- 
 \   “I watched the Indy 500, and I was thinking that if they left |
  `\ earlier they wouldn't have to go so fast.” —Steven Wright |
_o__)          |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] Posting under ones full name

2012-08-14 Thread Ben Finney
Chris Angelico  writes:

> On Wed, Aug 15, 2012 at 12:06 PM, Thomas 'PointedEars' Lahn
>  wrote:
> > Please use `[...]' or `[…]' to indicate omission instead. I could
> > have written `politeness...' myself.
>
> Incidentally, how _do_ the square brackets help?

They are a long-standing convention for marking an editorial addition or
clarification.

Square brackets – also called simply brackets (US) – are mainly used
to enclose explanatory or missing material usually added by someone
other than the original author, especially in quoted text.

https://en.wikipedia.org/wiki/Bracket#Square_brackets_.5B_.5D>

-- 
 \   “What I resent is that the range of your vision should be the |
  `\ limit of my action.” —Henry James |
_o__)      |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: email with a non-ascii charset in Python3 ?

2012-08-15 Thread Ben Finney
Steven D'Aprano  writes:

> On Wed, 15 Aug 2012 17:57:47 +0100, MRAB wrote:
>
> >> #!/usr/bin/python3
> >> #_*_ coding: latin1 _*_
> >>
> > Aw well as the other replies, the "coding" line should be:
> > 
> > #-*- coding: latin1 -*-
>
> I don't believe that actually matters to Python. It may matter to
> Emacs or some other editors

I think that is sufficient for MRAB's “should”. Especially since
Python's specification is designed so that people can write a valid
Emacs or Vim editor hint and have it work for Python.

-- 
 \  “The best mind-altering drug is truth.” —Jane Wagner, via Lily |
  `\    Tomlin |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


python-list@python.org

2012-08-17 Thread Ben Finney
Grant Edwards  writes:

> On 2012-08-16, Chris Angelico  wrote:
> > And FWIW, I add my voice to those who prefer to read replies
> > underneath the original text.
>
> Same here.  I often skip reading top-posted articles entirely, since I
> don't really care to take the time to start reading at the bottom,
> working my up, trying to figure out exactly what the poster is
> replying or referring to in the blob of context-free text at the top.

+1. A message which is top-posted is a fairly reliable indicator that
the message wasn't written with much consideration for the reader, so I
tend to just skip those messages.

If you don't care whether your messages are read, continue to top-post.

If you want to show that you've made efforts to make your message more
readable, use interleaved replies and trim off material to which you're
not replying http://brooksreview.net/2011/01/interleaved-email/>.

-- 
 \  “We tend to scoff at the beliefs of the ancients. But we can't |
  `\scoff at them personally, to their faces, and this is what |
_o__)         annoys me.” —Jack Handey |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Objects in Python

2012-08-22 Thread Ben Finney
lipska the kat  writes:

> If, in a language, I find I am able to say
>
> a = 1
>
> then later, in the same scope I can say
>
> a = "foo"
>
> then later again in the same scope I can say
>
> a = ([1,2,3], "xyz", True)
>
> then, and I may be missing something here, to me, that doesn't say
> strongly typed' that says 'no typing constraints whatsoever'

You haven't discovered anything about types; what you have discovered is
that Python name bindings are not variables.

In fact, Python doesn't have variables – not as C or Java programmers
would understand the term. What it has instead are references to objects
(with names as one kind of reference).

The documentation unfortunately calls these references “variables” in
various places, which IMO compounds the confusion in newcomers
experienced with other languages. It's best, I think, to reject the idea
that Python has variables, and think in terms of references instead.

Any reference (with some very narrow specific exclusions, like ‘None’)
can be re-bound to any other object without regard to the previous
binding.

> We need to separate out the 'view' from the 'implementation' here.
> Most developers I know, if looking at the code and without the
> possibly dubious benefit of knowing that in Python 'everything is an
> object' would not call this 'strong typing'

Those people are confused, then. Python is strongly typed: objects
always know their type, the type is always exact, and the type of an
object can't be changed.

This is always true regardless of whether the object is referred to
zero, one, or many times.

Python is dynamically typed: References (and hence names) don't have
types.

> It is OK to to make (possibly erroneous) observations isn't it?

One of our long-time regulars (Aahz, whom I haven't seen for a long
time, sadly) quipped that the best way to get correct information on
Usenet is not to ask a question, but to post incorrect information.
That's not a license for such behaviour, but an observation on its
effectiveness.

I'd say that so long as you phrase your assertions to indicate the level
of confidence and possibility of error, that's okay.

-- 
 \  “Generally speaking, the errors in religion are dangerous; |
  `\those in philosophy only ridiculous.” —David Hume, _A Treatise |
_o__)   of Human Nature_, 1739 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Objects in Python

2012-08-23 Thread Ben Finney
lipska the kat  writes:

> On 23/08/12 05:14, Steven D'Aprano wrote:
> > I think that's uncalled for.
[…]

> Excellent advice as usual, but I'm more than capable of looking after
> myself thank you.

As is usual, it's not all about you; Steven is demonstrating that we
require civil behaviour here, for anyone who may be watching but not
saying anything.

-- 
 \ “Skepticism is the highest duty and blind faith the one |
  `\   unpardonable sin.” —Thomas Henry Huxley, _Essays on |
_o__)   Controversial Questions_, 1889 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Objects in Python

2012-08-23 Thread Ben Finney
lipska the kat  writes:

> On 23/08/12 14:59, Ben Finney wrote:
> > lipska the kat  writes:
> >
> >> On 23/08/12 05:14, Steven D'Aprano wrote:
> >>> I think that's uncalled for.
> > […]
> >
> >> Excellent advice as usual, but I'm more than capable of looking after
> >> myself thank you.
> >
> > As is usual, it's not all about you; Steven is demonstrating that we
> > require civil behaviour here, for anyone who may be watching but not
> > saying anything.
>
> You 'require civil behaviour here' do you. Well so far I have been
> very civil.

And I say again: it's not all about you. Steven's respons was to a
different person in this thread. Please stop reacting as if everything
said around you is directed at you.

-- 
 \“I don't accept the currently fashionable assertion that any |
  `\   view is automatically as worthy of respect as any equal and |
_o__)   opposite view.” —Douglas Adams |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Objects in Python

2012-08-23 Thread Ben Finney
Steven D'Aprano  writes:

> No offence to Ben Finney, but I think sometimes he's a bit too eager
> to emphasise the subtle differences between Python and other
> languages, rather than the similarities.

No offense taken.

> Again, context is important:

Indeed. Note that my assertion was in response to someone *already*
confused by pre-conceived notions about what “variable” means, and
misguided attempts to apply those to Python.

If it's over-eager to attempt to head off such confusion in others who
might be reading, then I deny the charge. Others have said it helps, so
I'll keep doing it.

> I don't think the differences are important enough to *prohibit* use of 
> the word "variable" to describe name bindings. Only to discourage it.

I wholly agree.

-- 
 \ “Facts do not cease to exist because they are ignored.” —Aldous |
  `\Huxley |
_o__)          |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Variables vs names

2012-08-24 Thread Ben Finney
Steven D'Aprano  writes:

> On Thu, 23 Aug 2012 14:22:08 -0500, Evan Driscoll wrote:
>
> > In [the hypothetical language] Python--, any time you use a name,
> > you have to prefix it with the word 'variable':
> >   variable x = 4
> >   print(variable x)
> > 
> > Does Python-- have variables? 
>
> Of course, because that's what Python-- calls them. Whether Python--
> is *justified* in calling them variables is a more interesting
> question.

How many legs does a horse have, if you call the tail a leg?

Four. Calling the tail a leg doesn't make it so.


Similarly, I don't care that Python-- uses the term “variable”, it only
has variables if it has things which meet a sensible definition of
“variable”. So no, “because that's what Python-- calls them” is not
sufficient.

> I think it is, in the sense that name bindings are a kind of variable,
> and fixed memory locations are a different kind of variable. But I
> also think that it isn't, for exactly the reasons why I prefer to
> describe Python (without the minuses) as having name bindings rather
> than variables "in the C or Pascal sense".

To emphasise what may not be apparent to some newcomers, Steven and I
are virtually in exact agreement here. We talk more about where we
differ because that's what interests us :-)

-- 
 \  “In the long run, the utility of all non-Free software |
  `\  approaches zero. All non-Free software is a dead end.” —Mark |
_o__)Pilgrim, 2006 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Flexible string representation, unicode, typography, ...

2012-08-25 Thread Ben Finney
wxjmfa...@gmail.com writes:

> Unicode design: a flat table of code points, where all code
> points are "equals".

Yes, Unicode's design entails a flat table of hundreds of thousands of
code points, expansible in future.

This is in direct conflict with the design of all significant computers
we need to write software for: data stored and transported as 8-bit
bytes, which can only ever hold 256 different values, no expansion.

> As soon as one attempts to escape from this rule, one has to
> "pay" for it.

Yes, in either direction; the conflict means that trade-offs need to be
made.

See this presentation by Ned Batchelder, “Pragmatic Unicode”
http://nedbatchelder.com/text/unipain.html>, which lays out the
fundamental conflict of representing human text in computer data; and
several practical approaches to deal with it.

-- 
 \  “I busted a mirror and got seven years bad luck, but my lawyer |
  `\thinks he can get me five.” —Steven Wright |
_o__)      |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Computing win/loss records in Python

2012-08-25 Thread Ben Finney
Christopher McComas  writes:

> I have code that I run via Django that grabs the results from various
> sports from formatted text files. The script iterates over every line
> in the formatted text files, finds the team in the Postgres database
> updates their w/l record depending on the outcome on that line, saves
> the team's row in the db, and then moves on to the next line in the
> file.

It seems that you already have a PostgreSQL database storing this data.

> I'm trying to get away from Django for this project

That existing database can be accessed without Django. You could talk
directly using the ‘psycopg2’ library, but you don't have to go that
far.

I would recommend you use SQLAlchemy as a good and flexible way to
access existing databases (or make new ones) in a Pythonic manner
http://www.sqlalchemy.org/>. If you are using a free-software
operating system, you will likely already have packages available to
install SQLAlchemy from your operating system's package repositories.

-- 
 \ “True greatness is measured by how much freedom you give to |
  `\  others, not by how much you can coerce others to do what you |
_o__)       want.” —Larry Wall |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling External (Perl)Script in Python

2012-08-27 Thread Ben Finney
Pervez Mulla  writes:

> I am trying to call perl script in my python view.py and store that
> data in logfile 

To run external programs and connect to their standard streams, use the
‘subprocess’ module http://docs.python.org/library/subprocess.html>
from the Python standard library.

-- 
 \ “If we don't believe in freedom of expression for people we |
  `\   despise, we don't believe in it at all.” —Noam Chomsky, |
_o__)       1992-11-25 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: class object's attribute is also the instance's attribute?

2012-08-30 Thread Ben Finney
Hans Mulder  writes:

> Next week's lesson will be: if you test it first, then paste it into a
> message for this forum, then tweak just one unimportant detail, you'll
> need to test it again.

+1 QotW

-- 
 \“Look at it this way: Think of how stupid the average person |
  `\ is, and then realise half of 'em are stupider than that.” |
_o__)   —George Carlin, _Doin' It Again_, 1990 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Context manager to save/restore a name binding

2012-08-30 Thread Ben Finney
Howdy all,

I have written a context manager to save and restore a name binding::

import contextlib

@contextlib.contextmanager
def preserve_value(namespace, name):
""" A context manager to preserve, then restore, the specified binding.

:param namespace: The namespace object (e.g. a class or dict)
containing the name binding.
:param name: The name of the binding to be preserved.
:yield: None.

When the context manager is entered, the current value bound to 
`name`
in `namespace` is saved. When the context manager is exited, the
binding is re-established to the saved value.

"""
saved_value = getattr(namespace, name)
yield
setattr(namespace, name, saved_value)

The use case is http://stackoverflow.com/a/6811921/70157>, where
it's used like this::

with preserve_value(sys, 'dont_write_bytecode'):
sys.dont_write_bytecode = True
module = imp.load_module(…)

That way, I can set ‘sys.dont_write_bytecode’ to the value I need in
this part of the code, knowing that however the code continues the
previous value of that setting will be restored to whatever it was
before I touched it.

Have I re-invented a context manager which already exists? Is there a
better way to do what ‘preserve_value’ is doing?

-- 
 \   “When a well-packaged web of lies has been sold to the masses |
  `\over generations, the truth will seem utterly preposterous and |
_o__)its speaker a raving lunatic.” —Dresden James |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Context manager to save/restore a name binding

2012-08-31 Thread Ben Finney
Peter Otten <__pete...@web.de> writes:

> You should wrap yield in a try ... finally. You might allow setting
> the new value in the manager (untested):

Thank you, both good advice.

I would still like to know if Python already has something to make this
unnecessary.

-- 
 \  “Compulsory unification of opinion achieves only the unanimity |
  `\of the graveyard.” —Justice Roberts in 319 U.S. 624 (1943) |
_o__)      |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: thanks!

2012-08-31 Thread Ben Finney
Tim Chase  writes:

> Or we can take the opportunity to thank you for all your work on
> making this a relatively spam-free mailing list. So thanks!

Indeed. This forum has a very high signal-to-noise ratio, largely due to
efforts that are often invisible to the participants.

Thank you!

-- 
 \“The problem with television is that the people must sit and |
  `\keep their eyes glued on a screen: the average American family |
_o__) hasn't time for it.” —_The New York Times_, 1939 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The opener parameter of Python 3 open() built-in

2012-09-03 Thread Ben Finney
Dennis Lee Bieber  writes:

> On 04 Sep 2012 01:13:09 GMT, Steven D'Aprano
>  declaimed the following in
> gmane.comp.python.general:
> > What is the rationale for complicating [the builtin] open instead of
> > telling people to just call their opener directly?
>
>   To avoid the new syntax would mean coding the example as
>
>   f = os.fdopen(os.open("newfile", flags | os.O_EXCL), "w") 
>
> which does NOT look any cleaner to me... Especially not if "opener" is
> to be used in more than one location.

Exactly. That's not what was asked, though. Steven asked why not call
the opener.

So, having written the opener:

> On Mon, 03 Sep 2012 15:29:05 +0200, Christian Heimes wrote:
> > import os
> > 
> > def opener(file, flags):
> > return os.open(file, flags | os.O_EXCL)

why not call that directly?

f = opener(file, flags)

It certainly is cleaner than either of the alternatives so far, and it
doesn't add a parameter to the builtin.


> Furthermore, using "opener" could allow for a localized change to
> affect all open statements in the module -- change file path, open for
> string I/O rather than file I/O, etc.

I don't know of any real-life code which would be significantly improved
by that. Can you point us to some?

-- 
 \  “I find the whole business of religion profoundly interesting. |
  `\ But it does mystify me that otherwise intelligent people take |
_o__)it seriously.” —Douglas Adams |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The opener parameter of Python 3 open() built-in

2012-09-03 Thread Ben Finney
Ben Finney  writes:

> So, having written the opener:
>
> > On Mon, 03 Sep 2012 15:29:05 +0200, Christian Heimes wrote:
> > > import os
> > > 
> > > def opener(file, flags):
> > > return os.open(file, flags | os.O_EXCL)
>
> why not call that directly?
>
> f = opener(file, flags)

Ah, because that returns the file descriptor, not the file. I see.

-- 
 \ “If nature has made any one thing less susceptible than all |
  `\others of exclusive property, it is the action of the thinking |
_o__)      power called an idea” —Thomas Jefferson, 1813-08-13 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The opener parameter of Python 3 open() built-in

2012-09-03 Thread Ben Finney
Steven D'Aprano  writes:

> On Mon, 03 Sep 2012 23:19:51 -0400, Dennis Lee Bieber wrote:
> > f = os.fdopen(os.open("newfile", flags | os.O_EXCL), "w")
> > 
> > which does NOT look any cleaner to me... 
>
> Well, I don't know about that. Once you start messing about with low-
> level O_* flags, it's never going to exactly be clean no matter what you 
> do. But I think a one-liner like the above *is* cleaner than a three-
> liner like the original:
>
> def opener(file, flags):
> return os.open(file, flags | os.O_EXCL)
>
> open("newfile", "w", opener=opener)
>
> although I accept that this is a matter of personal taste.

If the opener has an unhelpful name like ‘opener’, yes.

But if it's named as any function should be named – to say what it does
that's special – then I think the result would be much clearer::

outfile = open("newfile", "w", opener=open_exclusive)

> Particularly if the opener is defined far away from where you
> eventually use it.

Another good reason to name helper functions descriptively.

> * or even more Pythonic, expose those numeric modes using strings:
>
>   open(file, 'wx')

Which is, indeed, another improvement in Python 3.3 – the ‘x’ mode for
‘open’ http://docs.python.org/dev/library/functions.html#open>.

-- 
 \“The greatest tragedy in mankind's entire history may be the |
  `\   hijacking of morality by religion.” —Arthur C. Clarke, 1991 |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


How to tell people to ask questions the smart way (was: focus on jtextfield)

2012-09-04 Thread Ben Finney
Andreas Perstinger  writes:

> On 04.09.2012 11:34, Paolo wrote:
> > how do I know if a JTextField has the focus?
> > thank to all
>
> Look there:
> http://www.catb.org/esr/faqs/smart-questions.html#forum

That is an unhelpful response. You aren't giving anything to help the
original poster improve their question. Moreover, it is rude and
dismissive, which doesn't belong in this forum.

The “how to ask question the smart way” essay is not a blunt instrument
for beating people over the head with, and it is brutish to use it that
way. Instead, please point out *how* the original poster's question can
be improved.

-- 
 \ “I think Western civilization is more enlightened precisely |
  `\ because we have learned how to ignore our religious leaders.” |
_o__)        —Bill Maher, 2003 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python docs search for 'print'

2012-09-04 Thread Ben Finney
Steven D'Aprano  writes:

> Gah! Brain meltdown! DDG does better on searches for Python terms with 
> fewer extraneous meanings, e.g. "python print" finds many links about 
> fashion, but https://duckduckgo.com/html/?q=python+tuple is all about 
> Python tuples :)

Adding the “site:docs.python.org” term will make any DuckDuckGo search
far more relevant to Python documentation.

https://duckduckgo.com/?q=site%3Adocs.python.org+print>

-- 
 \ “The truth is the most valuable thing we have. Let us economize |
  `\ it.” —Mark Twain, _Following the Equator_ |
_o__)          |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie: where's the new python gone?

2012-09-09 Thread Ben Finney
BobAalsma  writes:

> I think I've installed Python 2.7.3 according to the instructions in
> the README, and now want to use that version.

> However, when typing "python" in Terminal, I get "Python 2.6.4
> (r264:75821M, Oct 27 2009, 19:48:32) ".

I think you might have made a mistake.

Without more detail about what you did – detail which you perhaps can't
provide, since it's like asking “where did you last see the thing you
lost” – there's not much more we can do but guess.

You could try following the install instructions again, paying careful
attention to what might go wrong. Either something will go wrong, and
you'll be paying close enough attention to report it; or nothing will go
wrong, and you'll be able to use the version you want.

Good hunting.

-- 
 \ “The most dangerous man to any government is the man who is |
  `\   able to think things out for himself, without regard to the |
_o__)      prevailing superstitions and taboos.” —Henry L. Mencken |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing ISO date/time strings - where did the parser go?

2012-09-11 Thread Ben Finney
Roy Smith  writes:

> In article ,
>  Chris Angelico  wrote:
> > What is it that takes up forty pages [for the ISO 8601
> > specification]? RFC 2822 describes a date/time stamp in about two
> > pages. In fact, the whole RFC describes the Internet Message Format
> > in not much more than 40 pages. Is ISO-language just bloated?
> > 
> > *boggle*
>
> You can find a copy at http://dotat.at/tmp/ISO_8601-2004_E.pdf

In brief: ISO 8601 doesn't have the luxury of a single timestamp format.
It also must define its terms from a rather more fundamental starting
point than RFC 5822 can assume.

There's some bloat (5 of the 40 pages don't even show up in the table of
contents), but much of the content of the ISO 8601 standard is required,
to cover the ground intended in the level of detail intended.

Scope

This International Standard is applicable whenever representation of
dates in the Gregorian calendar, times in the 24-hour timekeeping
system, time intervals and recurring time intervals or of the
formats of these representations are included in information
interchange. It includes

* calendar dates expressed in terms of calendar year, calendar month
  and calendar day of the month;

* ordinal dates expressed in terms of calendar year and calendar day
  of the year;

* week dates expressed in terms of calendar year, calendar week number
  and calendar day of the week;

* local time based upon the 24-hour timekeeping system;

* Coordinated Universal Time of day;

* local time and the difference from Coordinated Universal Time;

* combination of date and time of day;

* time intervals;

* recurring time intervals.

-- 
 \   “First things first, but not necessarily in that order.” —The |
  `\  Doctor, _Doctor Who_ |
_o__)          |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a python license problem?

2012-09-11 Thread Ben Finney
Jayden  writes:

> Python is under GPL compatible. If I develop a python code

If you write new code, without deriving your work from the code of
Python itself, then the license of the Python code cannot affect what
you many do with what you wrote – because the copyright on Python does
not affect works not derived from it.

Despite the wishes of copyright maximalists (and the PSF are not
copyright maximalists, to my knowledge), there are still limits to the
scope of copyright.

> If python is under GPL, is the answer different? Thanks a lot!!

Python is not under GPL. But unless you are deriving a work from Python
and distributing the result, that doesn't alter the answer.

-- 
 \ “I wish there was a knob on the TV to turn up the intelligence. |
  `\  There's a knob called ‘brightness’ but it doesn't work.” |
_o__) —Eugene P. Gallagher |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Version of Python?

2012-09-11 Thread Ben Finney
"Charles Hottel"  writes:

> I have a lot of programming experience in many different languages and now 
> I want to learn Python.

Good for you, and welcome!

> Which version do you suggest I download, Python 2.x or Python 3.x ?
> Also why should I prefer one over the other?

This question is a good one. It is common enough that the home page
http://www.python.org/> has a link to the community's
answer/discussion at http://wiki.python.org/moin/Python2orPython3>.

> Right now I am thinkng Python 3.x as it has been out since 2008, but I
> have some concerns about backward compatibility with older packages
> that I might want to use.

The fact that Python 3 has been out for a number of years is important,
as is the fact that the Python developers and the community of
third-party library developers have worked quite hard to make it
feasible to work in Python 3.

More important, from the perspective of a newcomer, is that Python 2 is
essentially in maintenance-only mode, receiving only bug fixes. All
larger improvements are only going into Python 3.

The set of third-party libraries which are not ready for Python 3 still
has some significant members, and will certainly never be zero. But that
set has shrunk significantly in the many years that Python 3 has been
active.

At this stage, I would advise any person wanting to learn Python qua
Python (i.e. without considering the wrinkles of some specific task) to
focus on Python 3. If you need to learn older versions, that need will
present itself and you can learn the legacy quirks then; for now, learn
Python the way it is intended to be by going for Python 3.

-- 
 \  “A lie can be told in a few words. Debunking that lie can take |
  `\   pages. That is why my book… is five hundred pages long.” —Chris |
_o__)        Rodda, 2011-05-05 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Guides for communicating with business accounting systems

2012-09-13 Thread Ben Finney
Howdy all,

What material should a team of programmers read before designing a
database model and export format for sending commerce transactions to a
business accounting system?

I'm especially not wanting ad hoc advice in this thread; this is surely
an old, complex problem with a lot of ground already covered. Primers on
pitfalls to avoid and non-obvious best practices are what I'd like to be
directed toward.

Constraints:

* The shop is already written, and is maintained internally. Ideally we
  would use a widely-tested and third-party-maintained solution, but
  that's a struggle still ahead of us. For now, we must work with our
  private code base.

* None of the developer team are have much experience with the field of
  business accounting, so if possible we need to learn from the past
  design mistakes of others without making them ourselves.

* Our application is operating in Australia, with the sales tax tracking
  requirements that come with that. Australia-specific information is
  particularly desirable.

* The business has switched to a different accounting service recently;
  it may well change again soon. We want to at least consider robustness
  of our shop's transaction tracking design in the face of a possible
  future switch to a different accounting system.

I'm happy to asnwer questions, but I'm not about to hash out the design
in this thread; that's our development team's job.

What I want is pointers to a putative “What every programmer needs to
know about storing commercial transactions for business accounting”
general guide.

Does that information already exist where I can point our team to it?

-- 
 \   “I went to a general store. They wouldn't let me buy anything |
  `\ specifically.” —Steven Wright |
_o__)          |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Guides for communicating with business accounting systems

2012-09-13 Thread Ben Finney
Emile van Sebille  writes:

> The only standard I'm aware of is the EDI specification which I first
> encountered in the mid 70's and which is updated routinely. The full
> spec is the size of a telephone book (do they even still make those?)

Thanks, that's something to look into. And yes, in Melbourne we're still
getting phone books delivered.


Chris Angelico  writes:

> GST isn't particularly complicated, but again, be really REALLY clear
> what's going on. It's better to be massively verbose in the database
> and then squash things down for display than to be left wondering

Good advice, if depressing in its prospects.

> Don't use MySQL. :) Okay, that's hardly a *rule*, but it's a strong
> recommendation.

That's another struggle we have in our future, unfortunately.

-- 
 \   “If we listen only to those who are like us, we will squander |
  `\   the great opportunity before us: To live together peacefully in |
_o__)a world of unresolved differences.” —David Weinberger |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Obnoxious postings from Google Groups (was: datetime issue)

2012-09-16 Thread Ben Finney
Νικόλαος Κούρας  writes:

> Iam sorry i didnt do that on purpose and i dont know how this is done.
>
> Iam positng via google groups using chrome, thats all i know.

It is becoming quite clear that some change has happened recently to
Google Groups that makes posts coming from there rather more obnoxious
than before. And there doesn't seem to be much its users can do except
use something else.

Using Google Groups for posting to Usenet has been a bad idea for a long
time, but now it just seems to be a sure recipe for annoying the rest of
us. Again, not something you have much control over, except to stop
using Google Groups.

-- 
 \  “Actually I made up the term “object-oriented”, and I can tell |
  `\you I did not have C++ in mind.” —Alan Kay, creator of |
_o__)Smalltalk, at OOPSLA 1997 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: utcnow

2012-09-16 Thread Ben Finney
Nick the Gr33k  writes:

> Hello is there a better way of writing this:
>
> date = ( datetime.datetime.utcnow() + datetime.timedelta(hours=3)
> ).strftime( '%y-%m-%d %H:%M:%S')
>
> something like:
>
> date = datetime.datetime.utcnow(hours=3).strftime( '%y-%m-%d %H:%M:%S')
>
> i prefer it if it could be written as this.

Break long complicated statements into simpler statements. You might
need to get used to naming your intermediate results.

now = datetime.datetime.utcnow()
later = now + datetime.timedelta(hours=3)
timestamp_text = later.strftime("%Y-%m-%d %H:%M:%S")

> Also what about dayligh savings time?

What about it? What has your reading of the ‘datetime’ module
documentation taught you?

-- 
 \“Don't worry about people stealing your ideas. If your ideas |
  `\ are any good, you'll have to ram them down people's throats.” |
_o__)—Howard Aiken |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Docstring parsing and formatting

2012-09-17 Thread Ben Finney
Howdy all,

Where can I find a standard implementation of the docstring parsing and
splitting algorithm from PEP 257?


PEP 257 describes a convention of structure and formatting for
docstrings http://www.python.org/dev/peps/pep-0257/>. Docstrings
that conform to this convention can therefore be parsed into their
component parts, and re-formatted.

The PEP describes http://www.python.org/dev/peps/pep-0257/#id20>
and algorithm for parsing the docstring as found in the string literal.
It says “Docstring processing tools will …” and goes on to describe, in
prose and example code, how the parsing should be done.

Where is a common implementation of that algorithm? It seems that it
should be in the Python standard library, but I can't find it.

Ideally what I want is to be able to write:

import textwrap

(summary, description) = textwrap.pep257_parse(foo.__doc__)

and have ‘summary’ as the docstring's summary line, and ‘description’ as
the docstring's description (as described in http://www.python.org/dev/peps/pep-0257/#id19>).

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


SOLVED: Docstring parsing and formatting

2012-09-18 Thread Ben Finney
Joel Goldstick  writes:

> On Tue, Sep 18, 2012 at 1:03 AM, Terry Reedy  wrote:
> > On 9/17/2012 10:03 PM, Ben Finney wrote:
> >> Where can I find a standard implementation of the docstring parsing
> >> and splitting algorithm from PEP 257?
>
> Do you know about pydoc? I haven't looked at its source, but since it
> does a great job of printing documentation from docstrings it might
> contain what you need

Yes, I have now learned about the ‘pydoc’ module following the lead from
investigating the interactive interpreter's ‘help’ function
http://docs.python.org/library/pydoc.html>.

The ‘pydoc.splitdoc’ function, though not documented in the library
documentation, does what I need. It takes a docstring as input, and
returns a tuple of (synopsis, description).

Thanks to everyone who helped.

-- 
 \   “Value your freedom or you will lose it, teaches history. |
  `\ “Don't bother us with politics,” respond those who don't want |
_o__)           to learn.” —Richard Stallman, 2002 |
Ben Finney

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


Re: One of my joomla webpages has been hacked. Please help.

2012-09-22 Thread Ben Finney
Νίκος Γκρεεκ  writes:

> Τη Σάββατο, 22 Σεπτεμβρίου 2012 4:09:37 μ.μ. UTC+3, ο χρήστης Steven D'Aprano 
> έγραψε:
> > Why are we discussing this? It has nothing to do with Python and is
> > completely off-topic for this list.
>
> But how am i supposed to fix this vulnerability if i don't know which
> one is it?

This is not the forum to discuss it.

-- 
 \ “It is the fundamental duty of the citizen to resist and to |
  `\  restrain the violence of the state.” —Noam Chomsky, 1971 |
_o__)          |
Ben Finney

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


Right tool for the job (was: Exact integer-valued floats)

2012-09-22 Thread Ben Finney
Tim Roberts  writes:

> Apologize in advance for top-posting.  My Xoom makes bottom-posting
> awkward.

Surely the better solution, then, is to use a tool which does allow you
to compose a message properly – and abstain from posting until you get
to such a tool.

-- 
 \ “Those are my principles. If you don't like them I have |
  `\others.” —Groucho Marx |
_o__)      |
Ben Finney

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


Re: Editing Inkscape SVG files with Python?

2012-09-23 Thread Ben Finney
Steven D'Aprano  writes:

> I have some SVG files generated with Inkscape containing many text
> blocks (over 100). I wish to programmatically modify those text blocks
> using Python. Is there a library I should be using, or any other
> guidelines or advice anyone can give me?

My first step would be to use ‘lxml’ to manipulate an XML tree, since
that's what an SVG document contains.

Read the SVG file as a text string, de-serialise the text to an XML
tree. Match the nodes of interest using an XPath query, iterate over
them. Change the content of each node using Python text manipulation,
set the new value on the node. Re-serialise the tree to the SVG file.

-- 
 \   “I distrust those people who know so well what God wants them |
  `\to do to their fellows, because it always coincides with their |
_o__)  own desires.” —Susan Brownell Anthony, 1896 |
Ben Finney

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


Re: Who's laughing at my responses, and who's not?

2012-09-25 Thread Ben Finney
Dwight Hutto  writes:

> It's a little guy talk, and most seem to be guys.

Potty mouth is not “guy talk”, and sexism is not welcome here.

-- 
 \  “The opposite of a correct statement is a false statement. But |
  `\ the opposite of a profound truth may well be another profound |
_o__)  truth.” —Niels Bohr |
Ben Finney

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


Re: Stop feeding the trolls

2012-09-26 Thread Ben Finney
alex23  writes:

> On Sep 26, 5:06 pm, Dwight Hutto  wrote:
> > You can "Plonk" my dick bitches.
>
> You do understand that when you have so many people react badly to how
> you phrase things, that the problem most likely lies with you and not
> them? That the only person who actually reacts favourably to this
> garbage coming from you is *you*?

There have been ample opportunities for him to realise this. It's past
time to stop feeding this troll, please.

-- 
 \ “Alternative explanations are always welcome in science, if |
  `\   they are better and explain more. Alternative explanations that |
_o__) explain nothing are not welcome.” —Victor J. Stenger, 2001-11-05 |
Ben Finney

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


Re: unit testing class hierarchies

2012-10-02 Thread Ben Finney
Ulrich Eckhardt  writes:

> I want test_base() to be run as part of both TestD1 and TestD2,
> because it tests basic functions provided by both classes D1 and D2.

It sounds, from your description so far, that you have identified a
design flaw in D1 and D2.

The common functionality should be moved to a common code point (maybe a
base class of D1 and D2; maybe a function without need of a class). Then
you'll have only one occurrence of that functionality to test, which is
good design as well as easier test code :-)

-- 
 \  “When I was a little kid we had a sand box. It was a quicksand |
  `\   box. I was an only child... eventually.” —Steven Wright |
_o__)      |
Ben Finney

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


Use the appropriate forum for recruitment (was: Client Needs Linux Admin position in Pleasanton, CA)

2012-10-14 Thread Ben Finney
ram dev  writes:

> Good Day,
> We have an urgent Contract Opening in  Pleasanton, CA.

Please don't use this discussion forum for recruitment.

For Python job recruiters and seekers, we have a separate Python Job
Board http://www.python.org/community/jobs/>.

> Job Title: Linux Admin 

You should find a Linux job board for that.

-- 
 \   “I distrust those people who know so well what God wants them |
  `\to do to their fellows, because it always coincides with their |
_o__)  own desires.” —Susan Brownell Anthony, 1896 |
Ben Finney

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


Re: Aggressive language on python-list

2012-10-14 Thread Ben Finney
Zero Piraeus  writes:

> I'm a mostly passive subscriber to this list - my posts here over the
> years could probably be counted without having to take my socks off -
> so perhaps I have no right to comment, but I've noticed a marked
> increase in aggressive language here lately, so I'm putting my head
> above the parapet to say that I don't appreciate it.

Thanks for speaking up, Zero. You are certainly not alone in this.

“Ignore the trolls” is not helpful advice if one wants to maintain a
useful and friendly environment. If the hostile behaviour you refer to
goes unchallenged, the helpful contributors become drowned out and
eventually leave from fatigue. So ignoring trolls is not enough if we
want the friendly and useful conversations to continue.

Ignoring hostile behaviour also sends the wrong signal to newcomers and
casual observers: that this is not a community which cares about
actively upholding good standards of behaviour.

What's needed, IMO, is a difficult balance: there needs to be calm,
low-volume, but firm response to instances of hostile behaviour, making
clear by demonstration – especially to the people only observing the
discussion – that such hostility is unwanted and not to be tolerated in
our community.

This is difficult to achieve, though, because if *lots* of people do it,
the thread turns into a dogpile that is also unhelpful, and usually
departs from civil and rational discussion quickly. All of this turns
away more good people (again, often people who otherwise weeren't
involved in the particular discussion), so is counter-productive.

So my request is: Be selective, and be calm.


Don't respond deep in an existing exchange, especially one where many
others have already responded to that person. Be selective and only
respond when yours will be one of the first in the thread. (And that's
not a mandate to have a quick trigger :-)

Don't keep responding in a series of exchanges; it makes your messages
difficult for newcomers to tell apart from the voluminous noise of the
troll.

When responding to a troll, don't be inflammatory yourself – that is
*exactly* what they seek, a continuation and escalation of the conflict.

Point out exactly what you think they're doing wrong, simply and calmly,
and don't go on at length. Keep the innocent reader in mind, don't care
too much about the troll reading your response.

To those who feel the need to “fight” the trolls: thank you for caring
enough about the Python community to try to defend it. But I'm concerned
that you tend to pour fuel on the flames yourself, and I hope you can
work to avoid becoming the monster you fight.

> And, yes, I know bringing it up could be construed as stoking the
> flames ... but, well, "silence = acquiescence" and all that.

Agreed. Thanks again.

-- 
 \“Intellectual property is to the 21st century what the slave |
  `\  trade was to the 16th.” —David Mertz |
_o__)  |
Ben Finney

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


Re: Aggressive language on python-list

2012-10-16 Thread Ben Finney
"Kristen J. Webb"  writes:

> What the f**k! I thought that subscribing to a list would promote
> education, enlightenment, and a shared communal effort to make things
> better for things (python) related.

Yes, that's the focus of this thread: how best to engage in a shared
communal effort to make things better for Python-related discussion.

> It sucks for me to spend so much time filtering this BS.

The thread helpfully tells you what it's about in the subject field, and
remains remarkably on-topic by that description. Filter appropriately.

If it sucks for you to receive a high-volume discussion forum in your
email, you may want to use a better email client with more sophisticated
filtering capability. Or you can subscribe to the forum as a Usenet
newsgroup, news:comp.lang.python>.

> Let's be honest, does any of this crap have anything to do with
> python, it's promotion,

Yes, I think this discussion does have direct relevance to supporting
the promotion of Python. My views on how have been made elsewhere in
this same thread.

-- 
 \ “Teach a man to make fire, and he will be warm for a day. Set a |
  `\   man on fire, and he will be warm for the rest of his life.” |
_o__)         —John A. Hrastar |
Ben Finney

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


Deployment tools using Python (was: unittest for system testing)

2012-10-17 Thread Ben Finney
Rita  writes:

> Currently, I use a shell script to test how my system behaves before I
> deploy an application. For instance, I check if fileA, fileB, and
> fileC exist and if they do I go and start up my application.

The operating system shell, or the deployment framework of choice, is
best suited to that I think.

> This works great BUT
>
> I would like to use python and in particular unittest module to test my
> system and then deploy my app. I understand unittest is for functional
> testing

Well, unittest is for unit testing (testing of small isolated units of
the code). There are many definitions of “functional testing”, and I
don't think ‘unittest’ is a good choice for any of them.

> but I think this too would be a case for it.

Reserve the term “testing” for testing the code of your application, I'd
recommend. Libraries designed for “testing” are not good outside that
domain.

> Any thoughts?

If a shell program isn't up to the job, look at deployment tools like
Fabric http://pypi.python.org/pypi/Fabric/> or Salt
http://pypi.python.org/pypi/salt/>.

-- 
 \   “Two hands working can do more than a thousand clasped in |
  `\   prayer.” —Anonymous |
_o__)          |
Ben Finney

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


Re: A desperate lunge for on-topic-ness

2012-10-18 Thread Ben Finney
Zero Piraeus  writes:

> :
>

(Why is this colon appearing at the top of your messages? Can you remove
it if it's not germane?)

> What are people's preferred strategies for dealing with lines that go
> over 79 characters? A few I can think of off the bat:

> 1. Say "screw it" and go past 79, PEP8 be damned.

There are many people who are irritated by Python code that has lines
longer than 80 characters. In my experience, though, it's much easier to
read code which is written using a strict maximum length of 80
characters per line, and code which tends to exceed that length is
strongly correlated with code which is difficult to read for other
reasons too.

> 2. Say "screw it" and break the line using a backslash.

Never this. A backslash is almost never a good choice (it leaves the
code in a state that an invisible difference – trailing whitespace – can
cause it to break), especially because there are so many other better
options.

> 3. Say "well, at least it's not a backslash" and break the line using
> parentheses.

Long lines frequently have some kind of bracketing syntax (parentheses,
brackets, braces, triple-quotes, etc.) which make it easy to break the
line properly. That's a natural place to break the line, and the
continuations should all be indented 8 characters (recommended in PEP 8
also).

> 4. Spend 45 minutes trying to think up shorter [but still sensible]
> variable names to make it fit.

If the names are so long that they make it difficult to fit the line
within 80 characters, one of the following is probably true:

* The line is indented too far. Re-factor the chunk of code to a smaller
  function.

* The line is too complex. Break it into several smaller statements.

* The names are too long. Make them descriptive, but not huge. In a
  simple function (which all of them should ideally be) there should be
  few enough names involved that they can all be short. Corollary: if
  the names are too long, the function is probably too dependent on a
  large context.

> 5. Perform an otherwise pointless assignment to a temp variable on the
> previous line to make it fit.

Using assignments for intermediate steps is not pointless. One
significant benefit is that it makes the code more obvious to the
reader.

> 6. Realise that if it's that long, it probably shouldn't have been a
> list comprehension in the first place.

List comprehensions are already within bracketing syntax, so are
trivially easy to break across multiple lines.

> Any I've missed? Any preferences?

I prefer continuation lines to look like this::

def prepare_smorgasbord(
smorgasbord_class, poultry, food_preparation_handbook):
""" Prepare the smorgasbord with poultry.

The `food_preparation_handbook` is used to cite a warning if
a gizzard is past its expiration date.

"""
smorgasbord = smorgasbord_class()
for item in [
foo for foo in
poultry.giblets.iteritems()
if foo.type = 'gizzard']:
smorgasbord.add(
prepare_gizzard_for_consumption(item))
if item.expiry < datetime.datetime.now():
smorgasbord.flag(
food_preparation_handbook.warning("Only for the brave"))

return smorgasbord

Every statement should stay beyond the starting level of indentation;
returning to the same level of indentation or earlier should only happen
when a new statement occurs.

The 8-column indentation makes it clear that this is not a new code
block, making it obvious to the eye where a code block (indented at 4
columns) actually starts.

That's a contrived example, obviously, and for some of those things I'd
probably be tempted to re-factor self-contained parts to separate
functions in order to make the code at this location simpler. But it
illustrates the line continuation style I advocate.

-- 
 \“Program testing can be a very effective way to show the |
  `\presence of bugs, but is hopelessly inadequate for showing |
_o__)  their absence.” —Edsger W. Dijkstra |
Ben Finney

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


  1   2   3   4   5   6   7   8   9   10   >