Accessing a method from within its own code

2009-11-02 Thread Paddy O'Loughlin
Hi, I was wondering if there was a shorthand way to get a reference to a method object from within that method's code. Take this code snippet as an example: import re class MyClass(object): def find_line(self, lines): if not hasattr(MyClass.do_work, matcher):

Re: Accessing a method from within its own code

2009-11-02 Thread Paddy O'Loughlin
I suspect that the inspection module has your answer, but that it'll be bulkier, and much slower than just doing what you're doing already. Hmm. Yeah, it does appear to be bulky. I don't think it's really any more use than what I'm doing already. Why not use the default arguments gimmick?

Re: sorted() erraticly fails to sort string numbers

2009-04-30 Thread Paddy O'Loughlin
2009/4/30 Lie Ryan lie.1...@gmail.com container[:] = sorted(container, key=getkey) is equivalent to: container.sort(key=getkey) Equivalent, and in fact better since the sorting is done in-place instead of creating a new list, then overwriting the old one. Not when, as pointed

Reading an exact number of characters from input

2009-04-16 Thread Paddy O'Loughlin
Hi, How would I use python to simply read a specific number of characters from standard input? raw_input() only returns when the user inputs a new line (or some other special character). I tried import sys sys.stdin.read(15) and that *returns* up to 15 characters, but it keeps accepting input

Introducing Python to others

2009-03-26 Thread Paddy O'Loughlin
Hi, As our resident python advocate, I've been asked by my team leader to give a bit of a presentation as an introduction to python to the rest of our department. It'll be less than an hour, with time for taking questions at the end. There's not going to be a whole lot of structure to it. First,

Re: Introducing Python to others

2009-03-26 Thread Paddy O'Loughlin
Thanks for all your replies. A lot of very strong answers :) 2009/3/26 Mensanator mensana...@aol.com: What would you have to do to make this work? x+x+x      # expecting [3,6] [2, 4, 1, 2] What's happening is that the call to map() is returning a list object. So after it calculates the first

Re: Run a python script as an exe and run a new process from it

2009-02-27 Thread Paddy O'Loughlin
2009/2/27 venutaurus...@gmail.com venutaurus...@gmail.com: Thanks for the reply,,            I am trying to use the above application using psexec()in command line.But it failed returning the error message  exited with error code 255.              But when I ran the application normally it

Re: Run a python script as an exe and run a new process from it

2009-02-26 Thread Paddy O'Loughlin
Try this as an outline: script1.py from subprocess import Popen if __name__ == '__main__': scriptname = script2.py Popen(python %s % scriptname, shell=True) print I'm done script2.py from time import sleep if __name__ == '__main__': while (True):

Re: Byte type?

2009-02-24 Thread Paddy O'Loughlin
2009/2/24 John Nagle na...@animats.com: Martin v. Löwis wrote: Please don't call something dumb that you don't fully understand. It's offenses the people who have spent lots of time developing Python -- personal, unpaid and voluntary time!   Some of the people involved are on Google's

Re: How do I declare global vars or class vars in Python ?

2009-02-20 Thread Paddy O'Loughlin
2009/2/20 Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid: Note that while you *can* do direct access to the implementation attribute (here, '_A' for property 'A'), you don't *need* to so (and usually shouldn't - unless you have a very compelling reason). Interesting. Why

Re: How do I declare global vars or class vars in Python ?

2009-02-20 Thread Paddy O'Loughlin
2009/2/20 Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid: Interesting. Why shouldn't you? I haven't used the property() function s/function/object/ Nice try, but what I wrote was what I intended to say: http://docs.python.org/library/functions.html#property For all I know I

Re: How do I declare global vars or class vars in Python ?

2009-02-20 Thread Paddy O'Loughlin
2009/2/20 Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid: Check by yourself: import inspect inspect.isfunction(property) False Using this, every single builtin function returns False. That's a pretty limited definition to be being pedantic over, especially when they are in the

Re: How do I declare global vars or class vars in Python ?

2009-02-17 Thread Paddy O'Loughlin
Use the global statement. http://docs.python.org/reference/simple_stmts.html#the-global-statement A working example based on your pseudocode would be: def getA(): global A return A def getB(): global B return B def setA(value): global A

Re: How do I declare global vars or class vars in Python ?

2009-02-17 Thread Paddy O'Loughlin
2009/2/17 MRAB goo...@mrabarnett.plus.com: It isn't possible to have an uninitialised variable. If it doesn't have a value then it doesn't exist. True, but you can use the global statement to refer to the variable within a function and read from the variable there, without it being already

Re: Pythonic way to determine if a string is a number

2009-02-17 Thread Paddy O'Loughlin
2009/2/16 Python Nutter pythonnut...@gmail.com: silly me, forgot to mention build a set from digits + '.' and use that for testing. Cheers, PN 2009/2/16 Python Nutter pythonnut...@gmail.com: Type casting seems to be the wrong way to go about this. teststring = '15719'