Ensure unwanted names removed in class definition

2015-08-12 Thread Ben Finney
How can I ensure incidental names don't end up in the class definition, with code that works on both Python 2 and Python 3? With the following class definition, the incidental names `foo` and `bar`, only needed for the list comprehension, remain in the `Parrot` namespace:: __metaclass__ = obj

Is this a correct way to generate an exception when getting a wrong parameter

2015-08-12 Thread Cecil Westerhof
I have: accepted_params = { 'pcpu', 'rss', 'size', 'time', 'vsize', } Later I use: =

Re: Ensure unwanted names removed in class definition

2015-08-12 Thread Chris Angelico
On Wed, Aug 12, 2015 at 7:01 PM, Ben Finney wrote: > class Parrot: > """ A parrot with beautiful plumage. """ > > plumage = [ > (foo, bar) for (foo, bar) in feathers.items() > if bar == "beautiful"] > del foo, bar # ← FAILS, “NameError:

Re: Is this a correct way to generate an exception when getting a wrong parameter

2015-08-12 Thread Chris Angelico
On Wed, Aug 12, 2015 at 7:06 PM, Cecil Westerhof wrote: > I have: > > accepted_params = { > 'pcpu', > 'rss', > 'size', > 'time', > 'vsize', > } > ===

Re: Is this a correct way to generate an exception when getting a wrong parameter

2015-08-12 Thread Peter Otten
Cecil Westerhof wrote: > I have: > > accepted_params = { > 'pcpu', > 'rss', > 'size', > 'time', > 'vsize', > } > > > Later I us

Re: Is this a correct way to generate an exception when getting a wrong parameter

2015-08-12 Thread Mark Lawrence
On 12/08/2015 10:33, Peter Otten wrote: Cecil Westerhof wrote: I have: accepted_params = { 'pcpu', 'rss', 'size', 'time', 'vsize', }

Re: AttributeError

2015-08-12 Thread Denis McMahon
On Tue, 11 Aug 2015 17:01:24 -0700, Ltc Hotspot wrote: > What is the list equivalent to line 12: ncount.sort(reverse=True) > > count = dict() > fname = raw_input("Enter file name: ")# > handle = open (fname, 'r')# > for line in handle: > if line.startswith("From "): > address = line.s

Re: pyjs - a compiler from Python to JavaScript

2015-08-12 Thread Billy Earney
Uri, Brython on the other hand, tries to stay true to python (python compatible). As stated before it doesn't compile to stand alone Javascript, but the compile time is usually minimal. Access to Javascript libraries is supported. You really should give it a try.. http://brython.info Billy On

Re: AttributeError

2015-08-12 Thread MRAB
On 2015-08-12 04:05, Ltc Hotspot wrote: Chris, Check the code and the visualize execution of the code, available at http://tinyurl.com/p8tgd5h message reads: NameError: name 'collections' is not defined You didn't import the module. Regards, Hal On Tue, Aug 11, 2015 at 5:49 PM, Chris Ange

Re: AttributeError

2015-08-12 Thread MRAB
On 2015-08-12 06:03, Ltc Hotspot wrote: Message heard loud and clear: There are no error messages, the output is the issue. Question: What sorted function should I write to produce the desired output, below: Instead of iterating over "count.items()", iterate over "sorted(count.items())". D

Re: Ensure unwanted names removed in class definition

2015-08-12 Thread MRAB
On 2015-08-12 10:01, Ben Finney wrote: How can I ensure incidental names don't end up in the class definition, with code that works on both Python 2 and Python 3? With the following class definition, the incidental names `foo` and `bar`, only needed for the list comprehension, remain in the `Par

Re: Hooking Mechanism when Entering and Leaving a Try Block

2015-08-12 Thread Ian Kelly
On Tue, Aug 11, 2015 at 3:47 PM, Sven R. Kunze wrote: > is there something like a hook that a Python module could register to in > order to 'trace' the entering and leaving of arbitrary try blocks? Not that I'm aware of. However, it sounds like context managers might do what you want. You would

Re: pyjs - a compiler from Python to JavaScript

2015-08-12 Thread Uri Even-Chen
Thank you Billy, we will consider using Brython. Uri. *Uri Even-Chen* [image: photo] Phone: +972-54-3995700 Email: u...@speedy.net Website: http://www.speedysoftware.com/uri/en/

Re: Ensure unwanted names removed in class definition

2015-08-12 Thread Peter Otten
Ben Finney wrote: > How can I ensure incidental names don't end up in the class definition, > with code that works on both Python 2 and Python 3? > > With the following class definition, the incidental names `foo` and > `bar`, only needed for the list comprehension, remain in the `Parrot` > names

Re: AttributeError

2015-08-12 Thread Denis McMahon
On Tue, 11 Aug 2015 22:03:05 -0700, Ltc Hotspot wrote: > Question: What sorted function should I write to produce the desired > output, below: Me, I'd start by declaring a dictionary to hold the data: counts = { "{:02d}".format(h):0 for h in range(24) } Then I'd parse the strings in the log fil

Re: Ensure unwanted names removed in class definition

2015-08-12 Thread Chris Angelico
On Thu, Aug 13, 2015 at 1:39 AM, Peter Otten <__pete...@web.de> wrote: > But I would probably use a generator expression. These don't leak names: > > Python 2.7.6 (default, Jun 22 2015, 17:58:13) > [GCC 4.8.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. c

Re: Hooking Mechanism when Entering and Leaving a Try Block

2015-08-12 Thread Sven R. Kunze
Unfortunately, no. :( It should work out of the box with no "let me replace all my try-except statements in my 10 million line code base". On 12.08.2015 17:32, Ian Kelly wrote: On Tue, Aug 11, 2015 at 3:47 PM, Sven R. Kunze wrote: is there something like a hook that a Python module could re

Re: Hooking Mechanism when Entering and Leaving a Try Block

2015-08-12 Thread Chris Angelico
On Thu, Aug 13, 2015 at 2:05 AM, Sven R. Kunze wrote: > Unfortunately, no. :( > > It should work out of the box with no "let me replace all my try-except > statements in my 10 million line code base". (Please don't top-post.) Sounds to me like you want some sort of AST transform, possibly in an

ANN: eGenix mxODBC 3.3.4 - Python ODBC Database Interface

2015-08-12 Thread eGenix Team: M.-A. Lemburg
ANNOUNCING eGenix.com mxODBC Python ODBC Database Interface Version 3.3.4 mxODBC is our commercially supported Python extension providing

Python Book In Persian Language

2015-08-12 Thread foo foor
Hello, I'm Javad Mokhtari Koushyar from Iran, Hamedan. four month ago I started teaching python 3.4.1 in Persian using a blog. first I thought people do not pay attention to it but after a week I received very messages that makes me to continue and now I am happy that I made a book from my blog pos

Symbolic Links

2015-08-12 Thread Joshua Stokes
Hi I need help deleting broken symbolic links made by Python and/or Python modules Thanks >From Joshua P Stokes -- https://mail.python.org/mailman/listinfo/python-list

Re: Symbolic Links

2015-08-12 Thread Joshua Stokes
Never Mind Thanks >From Joshua P Stokes > On 12 Aug 2015, at 9:25 PM, Joshua Stokes > wrote: > > Hi > > I need help deleting broken symbolic links made by Python and/or Python > modules > > Thanks > > From Joshua P Stokes -- https://mail.python.org/mailman/listinfo/python-list

Re: AttributeError

2015-08-12 Thread Ltc Hotspot
Denis, Using the attached file of a diagram as a frame, why is there an attribute message? - Here is the attribute message: AttributeError Traceback (most recent call last) C:\Users\vm\Desk

Re: Ensure unwanted names removed in class definition

2015-08-12 Thread Jussi Piitulainen
Ben Finney writes: > How can I ensure incidental names don't end up in the class > definition, with code that works on both Python 2 and Python 3? > > With the following class definition, the incidental names `foo` and > `bar`, only needed for the list comprehension, remain in the `Parrot` > names

Re: Is this a correct way to generate an exception when getting a wrong parameter

2015-08-12 Thread Bernd Waterkamp
Mark Lawrence schrieb: > The wonderful http://docopt.org/ makes this type of thing a piece of > cake. I believe there's a newer library that's equivalent in > functionality to docopt but I can never remember the name of it, anybody? Never used it, but "Click" is another choice: http://click.po

Re: AttributeError

2015-08-12 Thread MRAB
On 2015-08-12 17:29, Ltc Hotspot wrote: Denis, Using the attached file of a diagram as a frame, why is there an attribute message? The code in the error report doesn't match the "revised code". ---

Python Book In Persian Language (fwd)

2015-08-12 Thread Laura Creighton
Are only English language blogs eligible for planet python? This showed up on Python list. I don't want to ask him if he wants to get his blog added if we have a language policy that I am unaware of. Laura --- Forwarded Message Date:Wed, 12 Aug 2015 17:37:41 +0430 To: python-list@p

Re: AttributeError

2015-08-12 Thread Ltc Hotspot
MRAB, I ran the code, and the output: Raw data code: handle = """From stephen.marqu...@uct.ac.za Sat Jan 5 09:14:16 2008 >From lo...@media.berkeley.edu Fri Jan 4 18:10:48 2008 """.split("\n") # Snippet file data: mbox-short.txt count = dict() #fname = raw_input("Enter file name: ")# Add Snipp

Extension build link error

2015-08-12 Thread garyr
I'm trying to build an extension module and was having problems so I decided to try something simpler. Article 16.5, "Coding the Methods of a Python Class in C" in the first edition of the Python Cookbook looked about right. I generated the code and a setup.py file (shown below). When I run python

Re: Python Book In Persian Language (fwd)

2015-08-12 Thread Laura Creighton
In a message of Wed, 12 Aug 2015 18:53:29 +0200, Laura Creighton writes: >Are only English language blogs eligible for planet python? >This showed up on Python list. I don't want to ask him if he wants to >get his blog added if we have a language policy that I am unaware of. > >Laura Oh rats, I d

Re: AttributeError

2015-08-12 Thread MRAB
On 2015-08-12 17:57, Ltc Hotspot wrote: MRAB, I ran the code, and the output: Raw data code: handle = """From stephen.marqu...@uct.ac.za Sat Jan 5 09:14:16 2008 >From lo...@media.berkeley.edu Fri Jan 4 18:10:48 2008 """.split("\n") # Snippet file data: mbox-short.txt count = dict() #fname =

RE: AttributeError

2015-08-12 Thread Clayton Kirkwood
> -Original Message- > From: Python-list [mailto:python-list- > bounces+crk=godblessthe...@python.org] On Behalf Of Ltc Hotspot > Sent: Wednesday, August 12, 2015 9:57 AM > To: MRAB > Cc: python-list@python.org > Subject: Re: AttributeError > > MRAB, > > I ran the code, and the output:

Re: Python Book In Persian Language (fwd)

2015-08-12 Thread M.-A. Lemburg
On 12.08.2015 18:53, Laura Creighton wrote: > Are only English language blogs eligible for planet python? > This showed up on Python list. I don't want to ask him if he wants to > get his blog added if we have a language policy that I am unaware of. Apparently, we do: https://github.com/python/p

Re: AttributeError

2015-08-12 Thread Emile van Sebille
On 8/12/2015 10:24 AM, MRAB wrote: What is it _actually_ trying to split? Aah, reading. Such an underused skill. Emile -- https://mail.python.org/mailman/listinfo/python-list

Re: AttributeError

2015-08-12 Thread Ltc Hotspot
Emile How do I define time in the revised code ? --- Traceback Message reads: In [66]: %run assignment_10_2_v_07 NameError Traceback (most recent call last) C:\Users\vm\Desktop\apps\docs\Pyt

Re: Hooking Mechanism when Entering and Leaving a Try Block

2015-08-12 Thread Sven R. Kunze
On 12.08.2015 18:11, Chris Angelico wrote: On Thu, Aug 13, 2015 at 2:05 AM, Sven R. Kunze wrote: Unfortunately, no. :( It should work out of the box with no "let me replace all my try-except statements in my 10 million line code base". (Please don't top-post.) Is this some guideline? I actu

Re: AttributeError

2015-08-12 Thread MRAB
On 2015-08-12 19:35, Ltc Hotspot wrote: Emile How do I define time in the revised code ? Have a look at assignment_10_2_v_06.py. --- Traceback Message reads: In [66]: %run assignment_10_2_v_07 NameError Traceback (most

Re: AttributeError

2015-08-12 Thread Ltc Hotspot
>Have a look at assignment_10_2_v_06.py. What should I look at assignment_10_2_v_06.py.: handle = """From stephen.marqu...@uct.ac.za Sat Jan 5 09:14:16 2008 >From lo...@media.berkeley.edu Fri Jan 4 18:10:48 2008 """.split("\n") # Snippet file data: mbox-short.txt count = dict() #fname = raw_i

Re: AttributeError

2015-08-12 Thread MRAB
On 2015-08-12 20:05, Ltc Hotspot wrote: >Have a look at assignment_10_2_v_06.py. What should I look at assignment_10_2_v_06.py.: How "time" is defined! handle = """From stephen.marqu...@uct.ac.za Sat Jan 5 09:14:16 2008 >From lo...@media.berkeley.edu Fri Jan 4 18:10:48 2008 """.split("\n")

Re: AttributeError

2015-08-12 Thread Denis McMahon
On Wed, 12 Aug 2015 09:29:50 -0700, Ltc Hotspot wrote: > Using the attached file of a diagram as a frame, why is there an > attribute message? Perhaps you should read the message. It's very clear. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-li

Re: AttributeError

2015-08-12 Thread Denis McMahon
On Wed, 12 Aug 2015 12:05:37 -0700, Ltc Hotspot wrote: >>Have a look at assignment_10_2_v_06.py. > What should I look at assignment_10_2_v_06.py.: You shouldn't. You should instead approach your tutor and tell him you are too stupid to learn computer programming[1], and can you please transfer

Re: Hooking Mechanism when Entering and Leaving a Try Block

2015-08-12 Thread Mark Lawrence
On 12/08/2015 19:44, Sven R. Kunze wrote: On 12.08.2015 18:11, Chris Angelico wrote: (Please don't top-post.) Is this some guideline? I actually quite dislike pick somebody's mail to pieces. It actually pulls things out of context. But if this is a rule for this, so be it. The rules here ar

Re: AttributeError

2015-08-12 Thread Mark Lawrence
On 12/08/2015 21:28, Denis McMahon wrote: On Wed, 12 Aug 2015 09:29:50 -0700, Ltc Hotspot wrote: Using the attached file of a diagram as a frame, why is there an attribute message? Perhaps you should read the message. It's very clear. Not to Ltc Hotspot. I'm unsure as to whether he's sim

RE: AttributeError

2015-08-12 Thread Clayton Kirkwood
I'm thinking we are being played by a Turing type machine. crk > -Original Message- > From: Python-list [mailto:python-list- > bounces+crk=godblessthe...@python.org] On Behalf Of Denis McMahon > Sent: Wednesday, August 12, 2015 1:39 PM > To: python-list@python.org > Subject: Re: Attribute

Re: AttributeError

2015-08-12 Thread Denis McMahon
On Wed, 12 Aug 2015 11:35:03 -0700, Ltc Hotspot wrote: > How do I define time in the revised code ? I'm guessing that you have a line of input like: word word word timestamp word word word word and that timestamp looks something like: hh:mm:ss Start of by defining a list with 24 elements all

Re: AttributeError

2015-08-12 Thread Gene Heskett
On Wednesday 12 August 2015 15:05:37 Ltc Hotspot wrote: > >Have a look at assignment_10_2_v_06.py. > > What should I look at assignment_10_2_v_06.py.: > > > handle = """From stephen.marqu...@uct.ac.za Sat Jan 5 09:14:16 2008 > From lo...@media.berkeley.edu Fri Jan 4 18:10:48 2008 > """.split("\n

Re: AttributeError

2015-08-12 Thread Emile van Sebille
On 8/12/2015 1:38 PM, Denis McMahon wrote: On Wed, 12 Aug 2015 12:05:37 -0700, Ltc Hotspot wrote: Have a look at assignment_10_2_v_06.py. What should I look at assignment_10_2_v_06.py.: You shouldn't. You should instead approach your tutor and tell him you are too stupid to learn computer

Re: AttributeError

2015-08-12 Thread Mark Lawrence
On 12/08/2015 22:15, Clayton Kirkwood wrote: I'm thinking we are being played by a Turing type machine. crk Will you please stop top posting, how many times do people have to be asked until the message gets through? -- My fellow Pythonistas, ask not what our language can do for you, ask wh

Re: AttributeError

2015-08-12 Thread Mark Lawrence
On 12/08/2015 22:32, Emile van Sebille wrote: @ltc -- read this -- then re-read all the responses you've been given. Repeat ad nauseam. Until you can understand and incorporate advice given you're wasting your time and ours asking. This question has been asked on *THREE* different Python mai

Re: AttributeError

2015-08-12 Thread Ltc Hotspot
The problem here is that these are home work assignment and to code an else word assignment would be in contradiction to the academic curriculum. Specifically, I want to deploy a quick and simply dic solution: Revised code: c = [0 for i in range(24)] filename = raw_input("Enter file name: ") f =

Re: AttributeError

2015-08-12 Thread Mark Lawrence
On 12/08/2015 23:02, Ltc Hotspot wrote: FOR GOD'S SAKE WILL YOU PLEASE STOP TOP POSTING AND TRIM DOWN YOUR REPLIES. WHAT GRADE DO YOU EXPECT, A Z-? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.

Re: AttributeError

2015-08-12 Thread MRAB
On 2015-08-12 22:16, Denis McMahon wrote: [snip] c = [0 for i in range(24)] f = open(filename,'r') for l in f: h = int(l.strip().split()[X].split(':')[Y]) c[h] = c[h] + 1 f.close() for i in range(24): print '{:02d} {}'.format(i, c[i]) There's no need to strip whitespace just bef

Re: Ensure unwanted names removed in class definition

2015-08-12 Thread Ben Finney
Peter Otten <__pete...@web.de> writes: > I would probably use a generator expression. These don't leak names: That's an unexpected inconsistency between list comprehensions versus generator expressions, then. Is that documented explicitly in the Python 2 documentation? > Python 2.7.6 (default, J

Re: Ensure unwanted names removed in class definition

2015-08-12 Thread Ben Finney
MRAB writes: > Have you thought about catching the NameError? I had not, but that is obvious now you say it. Thanks. Where there isn't a more elegant solution, I'll use that. It might not be elegant, but it's at least clear and expressive of the intent. Jussi Piitulainen writes: > Make them

Re: AttributeError

2015-08-12 Thread Ltc Hotspot
On Wed, Aug 12, 2015 at 3:35 PM, MRAB wrote: > On 2015-08-12 22:16, Denis McMahon wrote: > [snip] > >> c = [0 for i in range(24)] >> f = open(filename,'r') >> for l in f: >> h = int(l.strip().split()[X].split(':')[Y]) >> c[h] = c[h] + 1 >> f.close() >> for i in range(24): >> print '

Re: AttributeError

2015-08-12 Thread Emile van Sebille
On 8/12/2015 4:05 PM, Ltc Hotspot wrote: On Wed, Aug 12, 2015 at 3:35 PM, MRAB wrote: On 2015-08-12 22:16, Denis McMahon wrote: [snip] c = [0 for i in range(24)] f = open(filename,'r') for l in f: h = int(l.strip().split()[X].split(':')[Y]) c[h] = c[h] + 1 f.close() for i in range

Re: AttributeError

2015-08-12 Thread MRAB
On 2015-08-13 00:05, Ltc Hotspot wrote: On Wed, Aug 12, 2015 at 3:35 PM, MRAB wrote: > On 2015-08-12 22:16, Denis McMahon wrote: > [snip] > >> c = [0 for i in range(24)] >> f = open(filename,'r') >> for l in f: >> h = int(l.strip().split()[X].split(':')[Y]) >> c[h] = c[h] + 1 >> f.clos

Re: AttributeError

2015-08-12 Thread Ltc Hotspot
>> How do I define the file name in order to remove the traceback? >> > At this point I think I'll just let you figure that out for yourself... > > -- > https://mail.python.org/mailman/listinfo/python-list MRAB, How do I define X? --

Re: AttributeError

2015-08-12 Thread MRAB
On 2015-08-13 00:46, Ltc Hotspot wrote: >> How do I define the file name in order to remove the traceback? >> > At this point I think I'll just let you figure that out for yourself... > > -- > https://mail.python.org/mailman/listinfo/python-list MRAB, How do I define X?

Re: Hooking Mechanism when Entering and Leaving a Try Block

2015-08-12 Thread Chris Angelico
On Thu, Aug 13, 2015 at 6:54 AM, Mark Lawrence wrote: > On 12/08/2015 19:44, Sven R. Kunze wrote: >> >> On 12.08.2015 18:11, Chris Angelico wrote: >>> >>> (Please don't top-post.) >> >> >> Is this some guideline? I actually quite dislike pick somebody's mail to >> pieces. It actually pulls things

Re: Linux users: please run gui tests

2015-08-12 Thread Terry Reedy
On 8/8/2015 2:40 AM, Laura Creighton wrote: In a message of Fri, 07 Aug 2015 21:25:21 -0400, Terry Reedy writes: >> https://bugs.python.org/issue15601 was about this very test failure. The failure only occurred with tk 8.4. What tk version do you have? (Easily found, for instance, in Idle -

Re: Linux users: please run gui tests

2015-08-12 Thread Laura Creighton
In a message of Wed, 12 Aug 2015 21:49:24 -0400, Terry Reedy writes: >On 8/8/2015 2:40 AM, Laura Creighton wrote: >> In a message of Fri, 07 Aug 2015 21:25:21 -0400, Terry Reedy writes: > > >> https://bugs.python.org/issue15601 >>> was about this very test failure. The failure only occurred with t

Re: Ensure unwanted names removed in class definition

2015-08-12 Thread Peter Otten
Ben Finney wrote: > Peter Otten <__pete...@web.de> writes: > >> I would probably use a generator expression. These don't leak names: > > That's an unexpected inconsistency between list comprehensions versus > generator expressions, then. Is that documented explicitly in the Python > 2 documentat

Re: Ensure unwanted names removed in class definition

2015-08-12 Thread Ben Finney
Peter Otten <__pete...@web.de> writes: > Ben Finney wrote: > > > Peter Otten <__pete...@web.de> writes: > > > > That's an unexpected inconsistency between list comprehensions > > versus generator expressions, then. Is that documented explicitly in > > the Python 2 documentation? > > https://docs.

Re: Hooking Mechanism when Entering and Leaving a Try Block

2015-08-12 Thread Sven R. Kunze
On 13.08.2015 02:45, Chris Angelico wrote: On Thu, Aug 13, 2015 at 6:54 AM, Mark Lawrence wrote: On 12/08/2015 19:44, Sven R. Kunze wrote: On 12.08.2015 18:11, Chris Angelico wrote: (Please don't top-post.) Is this some guideline? I actually quite dislike pick somebody's mail to pieces. It

Re: Hooking Mechanism when Entering and Leaving a Try Block

2015-08-12 Thread Sven R. Kunze
On 12.08.2015 20:44, Sven R. Kunze wrote: On 12.08.2015 18:11, Chris Angelico wrote: Sounds to me like you want some sort of AST transform, possibly in an import hook. Check out something like MacroPy for an idea of how powerful this sort of thing can be. Sounds like I MacroPy would enable me