How do I DRY the following code?

2008-12-29 Thread R. Bernstein
How do I DRY the following code? class C(): def f1(self, arg1, arg2=None, globals=None, locals=None): ... unique stuff #1 ... ... some common stuff #1 ... ret = eval(args, globals, locals) ... more stuff #2 ... return retval def f2(self, arg1, arg2=None, *args,

Re: "return" in def

2008-12-29 Thread Aaron Brady
On Dec 29, 7:00 pm, Steven D'Aprano wrote: > On Mon, 29 Dec 2008 05:31:17 -0800, Aaron Brady wrote: > > One style of coding I heard about once only permits returns at the end > > of a function.  It claims it makes it easier to see the function as a > > mathematical object. > > That's silly. You tr

Re: Python in C

2008-12-29 Thread skip
thmpsn> 1. Can anyone explain to me what kind of program structuring thmpsn>technique (which paradigm, etc) CPython uses? How do modules thmpsn>interact together? What conventions does it use? it's quite object-oriented once you understand how things are done. Take a look, f

Re: Read-Write Lock vs primitive Lock()

2008-12-29 Thread Gabriel Genellina
En Mon, 29 Dec 2008 08:17:42 -0200, k3xji escribió: On 29 Aralık, 11:52, "Gabriel Genellina" wrote: En Mon, 29 Dec 2008 05:56:10 -0200, k3xji escribió: > I  am trying to see on which situations does the Read-Write Lock > performs better on primitive Lock() itself. Below is the code I am > u

Re: get method

2008-12-29 Thread Aaron Brady
On Dec 29, 8:02 pm, Steven D'Aprano wrote: > On Mon, 29 Dec 2008 17:38:36 -0800, Ross wrote: > > On Dec 29, 8:07 pm, Scott David Daniels wrote: > >> Ross wrote: > >> > ... Use get to write histogram more concisely. You should be able to > >> > eliminate the if statement. > > >> > def histogram(s)

Re: Python in C

2008-12-29 Thread David Cournapeau
On Tue, Dec 30, 2008 at 10:22 AM, wrote: > I've just downloaded Python's mainstream implementation (CPython), > which is written in C. Not to my surprise, I feel like I'm looking at > unstructured spaghetti, and I'm having trouble figuring out how it all > works together. (Please bear with me; I'

Re: multiprocessing vs thread performance

2008-12-29 Thread Aaron Brady
On Dec 29, 7:40 pm, "James Mills" wrote: > On Tue, Dec 30, 2008 at 11:34 AM, Aaron Brady wrote: > > The OP may be interested in Erlang, which Wikipedia (end-all, be-all) > > claims is a 'distribution oriented language'. snip > I'm presently looking at Virtual Synchrony and > other distributed pro

Re: multiprocessing vs thread performance

2008-12-29 Thread James Mills
On Tue, Dec 30, 2008 at 12:52 PM, Aaron Brady wrote: > On Dec 29, 7:40 pm, "James Mills" > wrote: >> On Tue, Dec 30, 2008 at 11:34 AM, Aaron Brady wrote: >> > The OP may be interested in Erlang, which Wikipedia (end-all, be-all) >> > claims is a 'distribution oriented language'. > snip >> I'm pr

print a vs print '%s' % a vs print '%f' a

2008-12-29 Thread David Cournapeau
Hi, While working on some python C extensions, I got curious in how things work for printing float objects (and C-level objects which inherit from it). In python 2.6, I understand that the formatting went into surgery for more consistency across platforms. So for example, on windows, complex('inf'

Re: Python module import loop issue

2008-12-29 Thread Gabriel Genellina
En Mon, 29 Dec 2008 19:47:51 -0200, Carl Banks escribió: On Dec 29, 10:51 am, Kottiyath wrote: Module Factory: A1Factory: {'B1Tag':1.1.B1, 'C1Tag':1.2.C1, 'D1Tag':1.3.D1'} A2Factory: {'B2Tag':2.1.B2, 'C2Tag':2.2.C2, 'D2Tag':2.3.D2'} But, since Module requires objects of B1, C1 etc, it has

Re: print a vs print '%s' % a vs print '%f' a

2008-12-29 Thread James Mills
On Tue, Dec 30, 2008 at 1:19 PM, David Cournapeau wrote: (... snip ...) > print '%f' % a # -> print '1.#INF' Would this not be controlled by: 1. float(a) or a.__float__() 2. tp_print cheers James -- http://mail.python.org/mailman/listinfo/python-list

Re: Python module import loop issue

2008-12-29 Thread Carl Banks
Gabriel Genellina wrote: > En Mon, 29 Dec 2008 19:47:51 -0200, Carl Banks > escribi�: > > On Dec 29, 10:51�am, Kottiyath wrote: > > >> Module Factory: > >> A1Factory: {'B1Tag':1.1.B1, 'C1Tag':1.2.C1, 'D1Tag':1.3.D1'} > >> A2Factory: {'B2Tag':2.1.B2, 'C2Tag':2.2.C2, 'D2Tag':2.3.D2'} > >> > >> But,

Re: print a vs print '%s' % a vs print '%f' a

2008-12-29 Thread David Cournapeau
On Tue, Dec 30, 2008 at 12:23 PM, James Mills wrote: > On Tue, Dec 30, 2008 at 1:19 PM, David Cournapeau wrote: > (... snip ...) > >> print '%f' % a # -> print '1.#INF' > > Would this not be controlled by: > 1. float(a) or a.__float__() > 2. tp_print Bah, I made a mistake in my example: complex(

Re: Python module import loop issue

2008-12-29 Thread Kottiyath
On Dec 30, 8:24 am, "Gabriel Genellina" wrote: > En Mon, 29 Dec 2008 19:47:51 -0200, Carl Banks   > escribió: > > > On Dec 29, 10:51 am, Kottiyath wrote: > >> Module Factory: > >> A1Factory: {'B1Tag':1.1.B1, 'C1Tag':1.2.C1, 'D1Tag':1.3.D1'} > >> A2Factory: {'B2Tag':2.1.B2, 'C2Tag':2.2.C2, 'D2Tag

Re: Python in C

2008-12-29 Thread Gabriel Genellina
En Tue, 30 Dec 2008 00:32:45 -0200, escribió: BTW, as a person who hasn't really written a stitch of C++ in about 10 years I personally find the CPython implementation to be one of the most well-organized large pieces of code I have ever encountered. It's much easier to read (to me) than any

Re: New Python 3.0 string formatting - really necessary?

2008-12-29 Thread Luis M . González
On Dec 29, 9:44 pm, Steven D'Aprano wrote: > How do you lose backward compatibility by *adding* new functionality? The > old functionality will continue to work as normal. > > -- > Steven AFAIK it still works the old way, but it will be deprecated soon. -- http://mail.python.org/mailman/listinfo/

Re: Of console I/O, characters, strings & dogs

2008-12-29 Thread John Machin
On Dec 30, 11:53 am, David Lemper wrote: > I am trying getch() from msvcrt. Unfortunately the msvcrt docs have not been 2to3ified: """ msvcrt.getch() Read a keypress and return the resulting character. Nothing is echoed to the console. This call will block if a keypress is not already available, b

Re: How do I DRY the following code?

2008-12-29 Thread Patrick Mullen
On Mon, Dec 29, 2008 at 6:13 PM, R. Bernstein wrote: > How do I DRY the following code? > > class C(): > > def f1(self, arg1, arg2=None, globals=None, locals=None): > ... unique stuff #1 ... > ... some common stuff #1 ... > ret = eval(args, globals, locals) > ... more stuff #2

Re: Get a list of functions in a file

2008-12-29 Thread member Basu
Thanks for all your replies, but the thing is I want to get the list of functions in that file itself, not by importing it as a module. I've decided to go with a class-based approach due to a number of other reasons, but I'm still interested in a way to get function name in that file itself. Thanks

How to debug embeding Python?

2008-12-29 Thread Hongtian
Hi Friends, My application is written in C/C++ and Python is embed to extend some functions (several .py files are invoked). But I am confused how to debug these embed Python? Can I use 'print-debuging'? and where can I capture the output string? Or Python can support 'break' debug for such scena

Re: Python 3.0 Curses Unicode

2008-12-29 Thread Damian Johnson
It seems as if the curses module in Python 3.0 isn't respecting the system's preferred encoding (utf-8) which was set via: locale.setlocale(locale.LC_ALL, '') The purpose of this was described at the top of ' http://docs.python.org/dev/3.0/library/curses.html#module-curses'. The getlocale function

Re: Python in C

2008-12-29 Thread akineko
Although this is not what you are asking but I'm wondering why you need to read CPython implementation. I have been using Python for 7 or 8 years but I've never encountered any situations where I need to read CPython implementation. I needed to read library implementations and installer codes, thou

<    1   2