Re: What do you guys think about adding a method "to_json"

2011-09-11 Thread Adam Jorgensen
Perhaps an actual use-case would clarify the need for this? 2011/9/12 Chris Rebert > 2011/9/11 Juan Pablo Romero Méndez : > > Hello, > > > > What do you guys think about adding a method "to_json" to dictionaries > > and sequence types? Perhaps through a module import? > > Why? We already have js

Re: What do you guys think about adding a method "to_json"

2011-09-11 Thread Chris Rebert
2011/9/11 Juan Pablo Romero Méndez : > Hello, > > What do you guys think about adding a method "to_json" to dictionaries > and sequence types? Perhaps through a module import? Why? We already have json.dumps(); seems to cover the use case. Cheers, Chris -- http://mail.python.org/mailman/listinfo

What do you guys think about adding a method "to_json"

2011-09-11 Thread Juan Pablo Romero Méndez
Hello, What do you guys think about adding a method "to_json" to dictionaries and sequence types? Perhaps through a module import? Regards, Juan Pablo -- http://mail.python.org/mailman/listinfo/python-list

Re: Doctest failing

2011-09-11 Thread Steven D'Aprano
On Mon, 12 Sep 2011 01:06 pm Chris Angelico wrote: > On Mon, Sep 12, 2011 at 11:37 AM, Ben Finney > wrote: >> Those are only practically the same if you ignore the practical worth of >> a function knowing the name it was defined with. The latter does not >> have that, hence I don't see it as prac

Re: Doctest failing

2011-09-11 Thread Chris Angelico
On Mon, Sep 12, 2011 at 11:37 AM, Ben Finney wrote: > Those are only practically the same if you ignore the practical worth of > a function knowing the name it was defined with. The latter does not > have that, hence I don't see it as practically the same as the former. > I know, but in the conte

Re: Doctest failing

2011-09-11 Thread Ben Finney
Chris Angelico writes: > A lambda is basically a function defined in an expression. For instance: > > def add_one(x): >return x+1 > > is (practically) the same as: > > add_one = lambda x: x+1 Those are only practically the same if you ignore the practical worth of a function knowing the name

Re: Doctest failing

2011-09-11 Thread Chris Angelico
On Mon, Sep 12, 2011 at 4:43 AM, Ethan Furman wrote: > Chris Angelico wrote: >> >> And I'd do this with a lambda, but that's just me. Of course, if your >> logic is more complicated, it makes more sense to keep it in a named >> function, but a single conditional call can fit nicely into a lambda.

Re: Idioms combining 'next(items)' and 'for item in items:'

2011-09-11 Thread Terry Reedy
On 9/11/2011 6:41 PM, Chris Angelico wrote: On Mon, Sep 12, 2011 at 2:47 AM, Terry Reedy wrote: What you are saying is a) that the following code for title in ['amazinG', 'a helL of a fiGHT', '', 'igNordEd']: print(fix_title(title)) At least in Python 3.2, this isn't the case. StopItera

Re: Idioms combining 'next(items)' and 'for item in items:'

2011-09-11 Thread Chris Angelico
On Mon, Sep 12, 2011 at 2:47 AM, Terry Reedy wrote: > What you are saying is a) that the following code > > for title in ['amazinG', 'a helL of a fiGHT', '', 'igNordEd']: >    print(fix_title(title)) > At least in Python 3.2, this isn't the case. StopIteration breaks the loop only if it's raised

Re: optionparse: how to add a line break to the help text

2011-09-11 Thread Robert Kern
On 9/11/11 6:05 AM, Tim Chase wrote: As Ben Finney replied, optparse is now deprecated, replaced in part by argparse. Unfortunately, argparse wasn't backported to the standard library for earlier 2.x series (I think it became available in 2.7, and may run in earlier versions if manually added li

Re: recursive algorithm for balls in numbered boxes

2011-09-11 Thread Peter Otten
Dr. Phillip M. Feldman wrote: > When I run my code, I get the same 14 configurations that your code > produces; I'm sorry, I ran the buggy code from http://old.nabble.com/file/p32439307/balls_in_numbered_boxes.py without realizing it was not http://old.nabble.com/file/p32440187/balls_in_numb

Re: using python in web applications

2011-09-11 Thread hidura
I am agree with postgresql i don' t have any problem, also is better for big applications. And Python is always better language than PHP if you' re going to create a web app. Sent from my BlackBerry® wireless device -Original Message- From: Tim Roberts Sender: python-list-bounces+hidura

Re: recursive algorithm for balls in numbered boxes

2011-09-11 Thread Dr. Phillip M. Feldman
Chris, Your code is much cleaner than mine. I will have to figure out exactly how it is working. Thanks! Phillip -- View this message in context: http://old.nabble.com/recursive-algorithm-for-balls-in-numbered-boxes-tp32440187p32443579.html Sent from the Python - python-list mailing list a

Re: recursive algorithm for balls in numbered boxes

2011-09-11 Thread Dr. Phillip M. Feldman
Hello Peter, When I run my code, I get the same 14 configurations that your code produces; the only different that I can see in the output is that the configurations are produced in a different order. Note that your code is not creating an iterator, so thus doesn't do what I want. Also, generat

Re: using python in web applications

2011-09-11 Thread Laurent
+1 for PostgreSQL. It's faster than MySQL for years now, and is much more seriously featured. If you don't need ACID properties (transactions stuff) you should also give Document-based databases like MongoDB a try. It changed my code life. -- http://mail.python.org/mailman/listinfo/python-list

Re: Idioms combining 'next(items)' and 'for item in items:'

2011-09-11 Thread Ethan Furman
Terry Reedy wrote: On 9/11/2011 12:01 AM, Ian Kelly wrote: On Sat, Sep 10, 2011 at 1:36 PM, Terry Reedy wrote: The statement containing the explicit next(items) call can optionally be wrapped to explicitly handle the case of an empty iterable in whatever manner is desired. try: except St

Re: using python in web applications

2011-09-11 Thread Tim Roberts
"Littlefield, Tyler" wrote: > >I don't much care for PHP, but the thing that can be said for it is it's >pretty quick. How does Python compare? PHP is quick for development, in that you can slap together some schlock and have it mostly work. The result, however, is usually schlock. The perform

Re: Doctest failing

2011-09-11 Thread Ethan Furman
Chris Angelico wrote: On Sat, Sep 10, 2011 at 10:24 PM, Alister Ware wrote: Ignoring the docttests my process would be to process each word & then manually capitalize he 1st word, .I would als0 use a comprehension as makes for cleaner code:- def capitalize(word): if word in small_words:

Re: Invoke a superclass method from a subclass constructor

2011-09-11 Thread Andreas Perstinger
On 2011-09-11 13:17, Kayode Odeyemi wrote: On Sun, Sep 11, 2011 at 11:41 AM, Thomas Jollans wrote: It is working: >>> class A(object): ... def log (self, module): ... return str ('logged') ... >>> class B(A): ... def __init__(self, module): ... self.module = A

Re: Idioms combining 'next(items)' and 'for item in items:'

2011-09-11 Thread Terry Reedy
On 9/11/2011 9:41 AM, Peter Otten wrote: Terry Reedy wrote: 3. Process the items of an iterable in pairs. items = iter(iterable) for first in items: second = next(items) This time, StopIteration is raised for an odd number of items. Catch and process as desired. One possibility i

Re: Doctest failing

2011-09-11 Thread Terry Reedy
On 9/11/2011 7:46 AM, Tigerstyle wrote: Thank you Terry, I went for this solution as it was the easiest for me to understand and comment myself keeping in mind what level I am at right now. Thanks a ton to everyone for sharing so much information and making it easy to read and understand your

Re: Doctest failing

2011-09-11 Thread Tigerstyle
On 11 Sep, 04:12, t...@thsu.org wrote: > On Sep 10, 7:47 am, Peter Otten <__pete...@web.de> wrote: > > > > > > > > > > > Tigerstyle wrote: > > > I'm strugglin with some homework stuff and am hoping you can help me > > > out here. > > > > This is the code: > > > > small_words = ('into', 'the', 'a',

Re: Doctest failing

2011-09-11 Thread Tigerstyle
On 11 Sep, 08:18, Dennis Lee Bieber wrote: > On Sat, 10 Sep 2011 16:25:42 -0700, Dennis Lee Bieber > declaimed the following in > gmane.comp.python.general: > > > > > in the language documentation... It will give you a simple way to know > > if you are looking at the first word. Basically, you wa

Re: Idioms combining 'next(items)' and 'for item in items:'

2011-09-11 Thread Terry Reedy
On 9/11/2011 12:01 AM, Ian Kelly wrote: On Sat, Sep 10, 2011 at 1:36 PM, Terry Reedy wrote: The statement containing the explicit next(items) call can optionally be wrapped to explicitly handle the case of an empty iterable in whatever manner is desired. try: except StopIteration: rai

Re: Doctest failing

2011-09-11 Thread Tigerstyle
On 10 Sep, 17:56, Chris Angelico wrote: > On Sat, Sep 10, 2011 at 10:24 PM, Alister Ware > > wrote: > > Ignoring the docttests my process would be to process each word & then > > manually capitalize he 1st word, .I would als0 use a comprehension as > > makes for cleaner code:- > > > def capitaliz

Re: Doctest failing

2011-09-11 Thread Tigerstyle
On 10 Sep, 13:43, Mel wrote: > Tigerstyle wrote: > > Hi guys. > > > I'm strugglin with some homework stuff and am hoping you can help me > > out here. > > > This is the code: > > > small_words = ('into', 'the', 'a', 'of', 'at', 'in', 'for', 'on') > > > def book_title(title): > >     """ Takes a st

Re: Doctest failing

2011-09-11 Thread Tigerstyle
On 10 Sep, 13:50, Thomas Jollans wrote: > On 10/09/11 13:20, Tigerstyle wrote: > > > Hi guys. > > > I'm strugglin with some homework stuff and am hoping you can help me > > out here. > > > All tests are failing even though I am getting the correct output on > > the first two tests. And the last te

Re: Deadlock problem using multiprocessing

2011-09-11 Thread Jacky Liu
> > I get this exception when I run the first program: > > Exception in thread Thread-1: > Traceback (most recent call last): >   File "/usr/lib/python3.1/threading.py", line 516, in _bootstrap_inner >     self.run() >   File "/usr/lib/python3.1/threading.py", line 469, in run >     self._target(*s

Re: recursive algorithm for balls in numbered boxes

2011-09-11 Thread Mark Dickinson
On Sep 11, 1:43 am, "Dr. Phillip M. Feldman" wrote: > I've written a recursive class that creates an iterator to solve a general > formulation of the combinatorics problem known as "balls in numbered boxes" > (also known as "indistinguishable balls in distinguishable boxes").  The > code has been

Re: optionparse: how to add a line break to the help text

2011-09-11 Thread Gelonida N
Thanks Ben, On 09/11/2011 07:20 AM, Ben Finney wrote: > Gelonida N writes: > >> Considering, that you posted the snippet in 2007 and this is very >> probably a reocurring problem for any slighty more complicated help >> text it is really a pity, that it did not become of part of the >> standard

Re: import packet.module without importing packet.__init__ ?

2011-09-11 Thread Gelonida N
Hi Steven, Thanks again for your answer. On 09/11/2011 06:51 AM, Steven D'Aprano wrote: > Gelonida N wrote: > > In your example, you stated that kitchen explicitly imports kitchen.pans and > kitchen.knives. So in that case, take it up with the designer of the > kitchen package -- it was his de

Re: Idioms combining 'next(items)' and 'for item in items:'

2011-09-11 Thread Peter Otten
Terry Reedy wrote: > 3. Process the items of an iterable in pairs. > > items = iter(iterable) > for first in items: > second = next(items) > > > This time, StopIteration is raised for an odd number of items. Catch and > process as desired. One possibility is to raise ValueError("Iter

Re: Doctest failing

2011-09-11 Thread Tigerstyle
On 10 Sep, 19:59, Terry Reedy wrote: > On 9/10/2011 7:20 AM, Tigerstyle wrote: > > > Hi guys. > > > I'm strugglin with some homework stuff and am hoping you can help me > > out here. > > We appreciate you saying so instead of hiding that this is homework. > > > > > > > > > > > small_words = ('into

Re: recursive algorithm for balls in numbered boxes

2011-09-11 Thread Peter Otten
Dr. Phillip M. Feldman wrote: > I've written a recursive class that creates an iterator to solve a general > formulation of the combinatorics problem known as "balls in numbered > boxes" > (also known as "indistinguishable balls in distinguishable boxes"). The > code has been extensively tested a

Re: Idioms combining 'next(items)' and 'for item in items:'

2011-09-11 Thread Tim Chase
On 09/10/11 14:36, Terry Reedy wrote: 1. Process first item of an iterable separately. A traditional solution is a flag variable that is tested for each item. first = True for item in iterable: if first: first = False else: (I have seen code like this posted on thi

Re: Invoke a superclass method from a subclass constructor

2011-09-11 Thread Dave Angel
On 01/-10/-28163 02:59 PM, Kayode Odeyemi wrote: Hello friends, An instance of my subclass doesn't invoke its superclass method, except when it is referenced directly. Here is what I mean: class A(object): ... def log(self, module): ... return str('logged') ... class B(A):

Re: Deadlock problem using multiprocessing

2011-09-11 Thread Kushal Kumaran
2011/9/11 蓝色基因 : > This is my first touch on the multiprocessing module, and I admit not > having a deep understanding of parallel programming, forgive me if > there's any obvious error. This is my test code: > > # deadlock.py > > import multiprocessing > > class MPTask: >        def __init__(self)

Re: Invoke a superclass method from a subclass constructor

2011-09-11 Thread Thomas Jollans
On 11/09/11 13:17, Kayode Odeyemi wrote: > On Sun, Sep 11, 2011 at 11:41 AM, Thomas Jollans > wrote: > > It is working: > > >>> class A(object): > ... def log (self, module): > ... return str ('logged') > ... > >>> class B(A): > ..

Re: Invoke a superclass method from a subclass constructor

2011-09-11 Thread Kayode Odeyemi
On Sun, Sep 11, 2011 at 11:41 AM, Thomas Jollans wrote: > On 11/09/11 10:18, Kayode Odeyemi wrote: > > Hello friends, > > > > An instance of my subclass doesn't invoke its superclass method, except > > when it is referenced > > directly. > > > > Here is what I mean: > > > class A(object): >

Re: optionparse: how to add a line break to the help text

2011-09-11 Thread Tim Chase
On 09/10/11 22:07, Gelonida N wrote: http://bytes.com/topic/python/answers/734066-how-output-newline-carriage-return-optparse It works (of course ;-) ) like a charm. Good to know, that I'm not the only one who want's to structure the help text a little nicer. Considering, that you posted the s

Re: Invoke a superclass method from a subclass constructor

2011-09-11 Thread Thomas Jollans
On 11/09/11 10:18, Kayode Odeyemi wrote: > Hello friends, > > An instance of my subclass doesn't invoke its superclass method, except > when it is referenced > directly. > > Here is what I mean: > class A(object): > ... def log(self, module): > ... return str('logged') > ..

Invoke a superclass method from a subclass constructor

2011-09-11 Thread Kayode Odeyemi
Hello friends, An instance of my subclass doesn't invoke its superclass method, except when it is referenced directly. Here is what I mean: >>> class A(object): ... def log(self, module): ... return str('logged') ... >>> class B(A): ... def __init__(self, module): ...