Re: [Tutor] How to run multiline shell command within python

2013-01-10 Thread Hugo Arts
On Thu, Jan 10, 2013 at 7:01 AM, Karim wrote: > > > Hello all, > > I want to run multiline shell command within python without using a > command file but directly execute several lines of shell. > I already use *subprocess.checkoutput("csh -f my_file.csh".split())* but I > want to know if it is p

Re: [Tutor] Flow charts

2013-01-10 Thread Alan Gauld
On 10/01/13 02:26, Ed Owens wrote: First, please start a new thread for a new topic, don't reply to an existing one. Threaded mail/news readers are not fooled by a simple change of subject so your post gets buried deep in an old thread. Just create a brand new mail to the list address. Anyway.

[Tutor] Problem with calling class methods stored in a list

2013-01-10 Thread Tobias Marquardt
Hello, I have a class with some class methods that are also stored in a list. Now I have a problem calling these methods. Essentially the relevant code looks like this: class MyClass(object): @classmethod def foo(cls): cls.method_list[0]() @classmethod def bar(cls):

Re: [Tutor] Problem with calling class methods stored in a list

2013-01-10 Thread Peter Otten
Tobias Marquardt wrote: > Hello, > > I have a class with some class methods that are also stored in a list. > Now I have a problem calling these methods. > Essentially the relevant code looks like this: > > class MyClass(object): > > @classmethod > def foo(cls): > cls.method_

Re: [Tutor] Problem with calling class methods stored in a list

2013-01-10 Thread Hugo Arts
On Thu, Jan 10, 2013 at 11:13 AM, Tobias Marquardt wrote: > Hello, > > I have a class with some class methods that are also stored in a list. > Now I have a problem calling these methods. > Essentially the relevant code looks like this: > > class MyClass(object): > > @classmethod > def fo

Re: [Tutor] Problem with calling class methods stored in a list

2013-01-10 Thread Tobias M.
Peter Otten wrote: Build the list outside the class: MyClass.method_list = [MyClass.bar] Thanks, that is a solution. But I don't really like to put the list outside the class as it is strongly related to the class and not used outside. Hugo Arts wrote: What piece of your code requires this li

Re: [Tutor] Problem with calling class methods stored in a list

2013-01-10 Thread Steven D'Aprano
On 10/01/13 21:13, Tobias Marquardt wrote: Hello, I have a class with some class methods that are also stored in a list. Now I have a problem calling these methods. Peter Otten has already given one solution. Read on for two more. Essentially the relevant code looks like this: class MyClass

Re: [Tutor] Problem with calling class methods stored in a list

2013-01-10 Thread Peter Otten
Tobias M. wrote: > Peter Otten wrote: >> Build the list outside the class: MyClass.method_list = [MyClass.bar] > Thanks, that is a solution. But I don't really like to put the list > outside the class as it is strongly related to the class and not used > outside. > Actually in my code it's not a

Re: [Tutor] Problem with calling class methods stored in a list

2013-01-10 Thread Tobias M.
Steven D'Aprano wrote: To answer your direct question, all you need to do is manually imitate what Python does when you call a descriptor (see below): py> MyClass.method_list[0].__get__(MyClass, None)() Hello World So, inside the foo() method, do this: @classmethod def foo(cls):

Re: [Tutor] Problem with calling class methods stored in a list

2013-01-10 Thread eryksun
On Thu, Jan 10, 2013 at 7:11 AM, Steven D'Aprano wrote: > > So, inside the foo() method, do this: > > @classmethod > def foo(cls): > cls.method_list[0].__get__(cls, None)() That should be cls.method_list[0].__get__(None, cls)() The way you have it binds the method to type(My

Re: [Tutor] Problem with calling class methods stored in a list

2013-01-10 Thread Tobias M.
Am 10.01.2013 13:57, schrieb eryksun: That should be cls.method_list[0].__get__(None, cls)() The way you have it binds the method to type(MyClass), which in this case is "type" itself. See cm_descr_get in funcobject.c, CPython 2.7 (line 645): http://hg.python.org/cpython/file/70274d53c1dd

Re: [Tutor] Problem with calling class methods stored in a list

2013-01-10 Thread eryksun
On Thu, Jan 10, 2013 at 7:48 AM, Peter Otten <__pete...@web.de> wrote: > > If you adopt this approach you might omit the lookup dictionary and use > getattr(): > class B(object): > ... @classmethod > ... def handle_foo(cls): print "Hello from B.handle_foo()" > ... @classmethod > ..

Re: [Tutor] Problem with calling class methods stored in a list

2013-01-10 Thread Tobias M.
Am 10.01.2013 13:48, schrieb Peter Otten: If you adopt this approach you might omit the lookup dictionary and use getattr(): ... @classmethod ... def handle_foo(cls): print "Hello from B.handle_foo()" ... @classmethod ... def get_handler(cls, packet_type): ... return

Re: [Tutor] Problem with calling class methods stored in a list

2013-01-10 Thread Dave Angel
On 01/10/2013 06:36 AM, Tobias M. wrote: > Peter Otten wrote: >> Build the list outside the class: MyClass.method_list = [MyClass.bar] > Thanks, that is a solution. But I don't really like to put the list > outside the class as it is strongly related to the class and not used > outside. But as it

Re: [Tutor] Problem with calling class methods stored in a list

2013-01-10 Thread Tobias M.
Tobias M. wrote: Well I think this is an elegant solution. But due to my protocol a packet type is uniquely defined by a combination of two header fields (that contain integers). Building a verbose method name from these would complicate it again. EDIT: I actually meant "meaningful method nam

Re: [Tutor] Problem with calling class methods stored in a list

2013-01-10 Thread Tobias M.
Dave Angel wrote: But as it's the simplest solution, and one with no runtime overhead, you really should consider it. Having a line or two following the class definition is not uncommon in Python, and comments can make sure the reader of the code understands it's part of the class initialization

[Tutor] garbage collection/class question

2013-01-10 Thread richard kappler
Class is still something I struggle with. I think I'm finally starting to get my head wrapped around it, but the discussion in a different thread has sparked a question. First, please check my understanding: A class creates objects, it's like a template that allows me to create as many copies as I

Re: [Tutor] Problem with calling class methods stored in a list

2013-01-10 Thread Peter Otten
Tobias M. wrote: > Am 10.01.2013 13:48, schrieb Peter Otten: >> If you adopt this approach you might omit the lookup dictionary and use >> getattr(): >> >> ... @classmethod >> ... def handle_foo(cls): print "Hello from B.handle_foo()" >> ... @classmethod >> ... def get_handler(cls,

Re: [Tutor] How to run multiline shell command within python

2013-01-10 Thread Karim
On 10/01/2013 09:31, Hugo Arts wrote: On Thu, Jan 10, 2013 at 7:01 AM, Karim > wrote: Hello all, I want to run multiline shell command within python without using a command file but directly execute several lines of shell. I already use *subprocess.c

Re: [Tutor] garbage collection/class question

2013-01-10 Thread Hugo Arts
On Thu, Jan 10, 2013 at 3:06 PM, richard kappler wrote: > Class is still something I struggle with. I think I'm finally starting to > get my head wrapped around it, but the discussion in a different thread has > sparked a question. First, please check my understanding: > A class creates objects, i

Re: [Tutor] garbage collection/class question

2013-01-10 Thread Dave Angel
On 01/10/2013 09:06 AM, richard kappler wrote: Since you don't specify Python version or implementation, I'll use CPython version 2.7 for the details below. Jython (for java environments) and other implementations are likely to differ in their garbage collection details. But the effect will be t

Re: [Tutor] Problem with calling class methods stored in a list

2013-01-10 Thread Tobias M.
Am 10.01.2013 15:15, schrieb Peter Otten: Of course handle_1_42() is not exactly the method name one would hope for. You could, again, strive for simplicity and add a lookup table that maps protocol tuples to function /names/ , but as simplicity doesn't seem to be your cup of tea: class Handlers

[Tutor] running multiple versions of python

2013-01-10 Thread Fowler, Trent
The archives aren't searchable or I would have started there. If there is a thread dealing with this, please send me there. I am running Windows 7 and I've installed two versions of python, 3.3 and 2.7. Python 3.3 was the first version I installed and I was able to run scripts from the desktop

Re: [Tutor] running multiple versions of python

2013-01-10 Thread eryksun
On Thu, Jan 10, 2013 at 11:34 AM, Fowler, Trent wrote: > > Python 3.3 was the first version I installed and I was able to run scripts > from the desktop (not the command line). I installed python 2.7 so that > I could get numpy, scipy, and matplotlib down the road, but I found that > all the scrip

Re: [Tutor] garbage collection/class question

2013-01-10 Thread Mitya Sirenef
On 01/10/2013 09:06 AM, richard kappler wrote: Class is still something I struggle with. I think I'm finally starting > to get my head wrapped around it, but the discussion in a different > thread has sparked a question. First, please check my understanding: > A class creates objects, it's lik

Re: [Tutor] running multiple versions of python

2013-01-10 Thread Alan Gauld
On 10/01/13 16:34, Fowler, Trent wrote: The archives aren't searchable The archives on ActiveState and gmane are. :-) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe o

Re: [Tutor] running multiple versions of python

2013-01-10 Thread Alan Gauld
On 10/01/13 16:34, Fowler, Trent wrote: Ideally I'd like to specify which python I want to run a script from the desktop Eryksun has mentioned the launchers but you can do this with standard Windows functionality. You just need to edit the file associations to create new extensions .py2 an

Re: [Tutor] How to run multiline shell command within python

2013-01-10 Thread Karim
On 10/01/2013 16:21, Matty Sarro wrote: Have you looked a the pexpect class? It works like gangbusters, especially if you're trying to run something with an interactive shell. http://www.noah.org/wiki/pexpect On Thu, Jan 10, 2013 at 9:25 AM, Karim > wrote: On

Re: [Tutor] Problem with calling class methods stored in a list

2013-01-10 Thread Steven D'Aprano
On 10/01/13 23:57, eryksun wrote: On Thu, Jan 10, 2013 at 7:11 AM, Steven D'Aprano wrote: So, inside the foo() method, do this: @classmethod def foo(cls): cls.method_list[0].__get__(cls, None)() That should be cls.method_list[0].__get__(None, cls)() Oops, yes, tha