Re: import and package confusion

2009-05-01 Thread alex23
On May 1, 4:24 pm, Arnaud Delobelle wrote: > It's a challenge to do it in a list comprehension, but here it is! > >>> data > 'AAABCDD' > >>> field_sizes > [3, 5, 9, 2] > >>> [data[i:j] for j in [0] for s in field_sizes for i, j in [(j, j+s)]] > ['AAA', 'B', 'C', 'DD'] Ugh.

Re: Modifying the value of a float-like object

2009-05-01 Thread smichr
On May 1, 11:13 am, smichr wrote: > Also, this approach is limited in that only variables can be arguments > to functions, not node expressions. If x and d are variables, x/d > becomes an expression and you cannot compute sin(x/d). Or am I missing > something? > Note to self...it's best to restar

Re: Why bool( object )?

2009-05-01 Thread Paul Rubin
Steven D'Aprano writes: > for x in a or b or c: > do_something_with(x) Ugh for x in [a,b,c]: if len(x) > 0: do_something_with(x) break -- http://mail.python.org/mailman/listinfo/python-list

Re: list comprehension question

2009-05-01 Thread thor
On May 1, 2:28 pm, Arnaud Delobelle wrote: > Ross writes: > > If I have a list of tuples a = [(1,2), (3,4), (5,6)], and I want to > > return a new list of each individual element in these tuples, I can do > > it with a nested for loop but when I try to do it using the list > > comprehension b = [

Re: urllib2 and threading

2009-05-01 Thread Paul Rubin
robean writes: > reach the urls with urllib2. The actual program will involve fairly > elaborate scraping and parsing (I'm using Beautiful Soup for that) but > the example shown here is simplified and just confirms the url of the > site visited. Keep in mind Beautiful Soup is pretty slow, so if y

Re: subprocess & shared environments

2009-05-01 Thread Piet van Oostrum
> Robert Dailey (RD) wrote: >RD> I'm currently calling subprocess.call() on a batch file (in Windows) >RD> that sets a few environment variables that are needed by further >RD> processes started via subprocess.call(). How can I persist the >RD> environment modifications by the first call() fu

How to measure the memory cost in Python?

2009-05-01 Thread Li Wang
Hi everyone: I want to measure the actual memory cost of a particular step in my program (Python program), does anyone know if there is some function in Python could help me to do this job? Or should I seek other tools to help me? Thank you very much! -- Li -- Time is all we have and you ma

Re: string processing question

2009-05-01 Thread Kurt Mueller
Paul McGuire schrieb: > -- > Weird. What happens if you change the second print statement to: > print b.center(6,u"-") Same behavior. I have an even more minimal example: :> python -c 'print unicode("ä", "utf8")' ä :> python -c 'print unicode("ä", "utf8")' | cat Traceback (most recent call las

Re: Why bool( object )?

2009-05-01 Thread Steven D'Aprano
On Fri, 01 May 2009 00:22:22 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> for x in a or b or c: >> do_something_with(x) > > Ugh > > for x in [a,b,c]: > if len(x) > 0: >do_something_with(x) >break What ugly, wasteful code. And it's *wrong* -- it doesn't d

Re: How to measure the memory cost in Python?

2009-05-01 Thread Chris Rebert
On Fri, May 1, 2009 at 1:03 AM, Li Wang wrote: > Hi everyone: > > I want to measure the actual memory cost of a particular step in my program > (Python program), does anyone know if there is some function in Python could > help me to do this job? Or should I seek other tools to help me? See Gabri

Re: Multiprocessing.Queue - I want to end.

2009-05-01 Thread Hendrik van Rooyen
"Luis Zarrabeitia" wrote: 8< ---explanation and example of one producer, 8< ---more consumers and one queue >As you can see, I'm sending one 'None' per consumer, and hoping that no >consumer will read more than one None. While this particular implementatio

returning values of a particular key from a dictionary

2009-05-01 Thread Saurabh
arr = ({'x':'1', 'y':'a'}, {'x':'2', 'y':'b'}, {'x':'3', 'y':'c'}) print foo(arr, 'y') ['a','b','c'] I can write the function foo to return ['a','b','c']. Is there some 'automatic'/built-in way to get this in Python ? -- Phonethics -- http://mail.python.org/mailman/listinfo/python-list

Re: Why bool( object )?

2009-05-01 Thread Paul Rubin
Steven D'Aprano writes: > (2) Why assume that a, b and c are sequences with a fast __len__ method? > They might be (say) linked lists that take O(N) to calculate the length, > or binary trees that don't even have a length, but can be iterated over. Why assume they have a bool method? Or a __or

Re: returning values of a particular key from a dictionary

2009-05-01 Thread Paul Rubin
Saurabh writes: > arr = ({'x':'1', 'y':'a'}, {'x':'2', 'y':'b'}, {'x':'3', 'y':'c'}) > print foo(arr, 'y') > ['a','b','c'] print list(a['y'] for a in arr) -- http://mail.python.org/mailman/listinfo/python-list

Re: Why bool( object )?

2009-05-01 Thread Hendrik van Rooyen
"Paul Rubin" wrote: > Steven D'Aprano writes: > > for x in a or b or c: > > do_something_with(x) > > Ugh > > for x in [a,b,c]: > if len(x) > 0: >do_something_with(x) >break > Ugh for x in [a,b,c]: if x: do_something_wi

Re: returning values of a particular key from a dictionary

2009-05-01 Thread Chris Rebert
On Fri, May 1, 2009 at 1:53 AM, Saurabh wrote: > arr = ({'x':'1', 'y':'a'}, {'x':'2', 'y':'b'}, {'x':'3', 'y':'c'}) > print foo(arr, 'y') > ['a','b','c'] > > I can write the function foo to return ['a','b','c']. > Is there some 'automatic'/built-in way to get this in Python ? from operator import

Re: bug with os.rename in 2.4.1?

2009-05-01 Thread Steven D'Aprano
On Thu, 30 Apr 2009 03:30:04 -0500, Nick Craig-Wood wrote: >> The race condition is still there. The only difference is that in the >> first case it fails noisily, with an exception, and in the second it >> fails quietly and does nothing. > > I'd argue that since os.rename implements the sysca

Re: returning values of a particular key from a dictionary

2009-05-01 Thread John O'Hagan
On Fri, 1 May 2009, Saurabh wrote: > arr = ({'x':'1', 'y':'a'}, {'x':'2', 'y':'b'}, {'x':'3', 'y':'c'}) > print foo(arr, 'y') > ['a','b','c'] > > I can write the function foo to return ['a','b','c']. > Is there some 'automatic'/built-in way to get this in Python ? List comprehension: [i['y'] for

Re: string processing question

2009-05-01 Thread Kurt Mueller
Scott David Daniels schrieb: > To discover what is happening, try something like: > python -c 'for a in "ä", unicode("ä"): print len(a), a' > > I suspect that in your encoding, "ä" is two bytes long, and in > unicode it is converted to to a single character. :> python -c 'for a in "ä", unicode

Re: Light (general) Inter-Process Mutex/Wait/Notify Synchronization?

2009-05-01 Thread Lawrence D'Oliveiro
In message <49f729f5$0$1645$742ec...@news.sonic.net>, John Nagle wrote: > Linux doesn't do interprocess communication very well. > ... and shared memory (unsafe). What about with a futex? -- http://mail.python.org/mailman/listinfo/python-list

Re: Why bool( object )?

2009-05-01 Thread Steven D'Aprano
On Fri, 01 May 2009 01:56:50 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> (2) Why assume that a, b and c are sequences with a fast __len__ >> method? They might be (say) linked lists that take O(N) to calculate >> the length, or binary trees that don't even have a length, but can be >> i

Re: Replacing files in a zip archive

2009-05-01 Thread Дамјан Георгиевски
> Which will produce the same output as the original, confounding > your user. You could just write the new values out, since .read > picks the last entry (as I believe it should). Alternatively, if > you want to replace it "in place", you'll need a bit more smarts > when there is more than one c

Re: string processing question

2009-05-01 Thread Sion Arrowsmith
Kurt Mueller wrote: >:> python -c 'print unicode("ä", "utf8")' >ä > >:> python -c 'print unicode("ä", "utf8")' | cat >Traceback (most recent call last): > File "", line 1, in >UnicodeEncodeError: 'ascii' codec can't encode characters in position >0-1: ordinal not in range(128) $ python -c 'imp

problem in with keyword

2009-05-01 Thread Murali kumar
hi all.. my application runs fine in windows xp using python 2.6 and wxpython 2.8.9 but in ubuntu 8.10 following error appears.. using python 2.5.2 and wxpython 2.8.9 /home/murali/Desktop/mathdemo-configfinal/manageprofile.py:63: Warning: 'with' will become a reserved keyword in Python 2.6 Trac

Re: problem in with keyword

2009-05-01 Thread Chris Rebert
On Fri, May 1, 2009 at 3:56 AM, Murali kumar wrote: > hi all.. > > my application runs fine in windows xp using python 2.6 and wxpython 2.8.9 > > but in ubuntu 8.10 following error appears..  using python 2.5.2 and > wxpython 2.8.9 > > /home/murali/Desktop/mathdemo-configfinal/manageprofile.py:63:

Dynamically declared shared constant/variable imported twice problem

2009-05-01 Thread Gabriel Rossetti
Hello everyone, I have three modules A, B, C; A declares this globally : UpdateEvent, UPDATE_EVENT_ID = wx.lib.newevent.NewEvent() Then they import stuff from each other: - A imports a constant from module B (in "__main__") - A imports a class and some constants from module C - B imports a c

where to start with

2009-05-01 Thread venky
Hi, As iam very new to python i would like explore python. Can any body guide me as your guidance is more worth than googling and finding it. Thanks, Venkat http://www.prog2impress.com/ -- http://mail.python.org/mailman/listinfo/python-list

Generator oddity

2009-05-01 Thread opstad
I'm a little baffled by the inconsistency here. Anyone have any explanations? >>> def gen(): ... yield 'a' ... yield 'b' ... yield 'c' ... >>> [c1 + c2 for c1 in gen() for c2 in gen()] ['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc'] >>> list(c1 + c2 for c1 in gen() for c2 in gen()) [

Re: where to start with

2009-05-01 Thread Chris Rebert
On Fri, May 1, 2009 at 4:37 AM, venky wrote: > Hi, > > As iam very new to python i would like explore python. Can any body > guide me as your guidance is more worth than googling and finding it. Good tutorials: http://docs.python.org/tutorial/ http://diveintopython.org/toc/index.htm http://openbo

Re: Dynamically declared shared constant/variable imported twice problem

2009-05-01 Thread Peter Otten
Gabriel Rossetti wrote: > I have three modules A, B, C; > > A declares this globally : > > UpdateEvent, UPDATE_EVENT_ID = wx.lib.newevent.NewEvent() > > Then they import stuff from each other: > > - A imports a constant from module B (in "__main__") > - A imports a class and some constants f

Re: Generator oddity

2009-05-01 Thread Pascal Chambon
ops...@batnet.com a écrit : I'm a little baffled by the inconsistency here. Anyone have any explanations? def gen(): ... yield 'a' ... yield 'b' ... yield 'c' ... [c1 + c2 for c1 in gen() for c2 in gen()] ['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc']

Re: Generator oddity

2009-05-01 Thread Steven D'Aprano
On Fri, 01 May 2009 04:58:16 -0700, opstad wrote: > I'm a little baffled by the inconsistency here. Anyone have any > explanations? > def gen(): > ... yield 'a' > ... yield 'b' > ... yield 'c' > ... [c1 + c2 for c1 in gen() for c2 in gen()] > ['aa', 'ab', 'ac', 'ba', 'bb', 'bc', '

Re: Generator oddity

2009-05-01 Thread Duncan Booth
ops...@batnet.com wrote: it1 = gen() it2 = gen() list(c1 + c2 for c1 in it1 for c2 in it2) > ['aa', 'ab', 'ac'] > > Why does this last list only have three elements instead of nine? First time through the c1 in it1 loop you use up all of the it2 values. Second and third times thro

Re: Generator oddity

2009-05-01 Thread opstad
D'oh! Many thanks for the explanation; I should have seen that myself. -- http://mail.python.org/mailman/listinfo/python-list

Re: Dynamically declared shared constant/variable imported twice problem

2009-05-01 Thread Gabriel Rossetti
Peter Otten wrote: Gabriel Rossetti wrote: I have three modules A, B, C; A declares this globally : UpdateEvent, UPDATE_EVENT_ID = wx.lib.newevent.NewEvent() Then they import stuff from each other: - A imports a constant from module B (in "__main__") - A imports a class and some consta

Re: string processing question

2009-05-01 Thread Kurt Mueller
Sion Arrowsmith wrote: > Kurt Mueller wrote: >> :> python -c 'print unicode("ä", "utf8")' >> ä >> :> python -c 'print unicode("ä", "utf8")' | cat >> Traceback (most recent call last): >> File "", line 1, in >> UnicodeEncodeError: 'ascii' codec can't encode characters in position >> 0-1: ordinal n

Re: Generator oddity

2009-05-01 Thread Dave Angel
ops...@batnet.com wrote: I'm a little baffled by the inconsistency here. Anyone have any explanations? def gen(): ... yield 'a' ... yield 'b' ... yield 'c' ... [c1 + c2 for c1 in gen() for c2 in gen()] ['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc']

Re: Generator oddity

2009-05-01 Thread Andre Engels
On Fri, May 1, 2009 at 4:25 PM, Dave Angel wrote: > The problem is in it2, which is initialized only once.  Thus the second time > you're going through the c2 loop, it doesn't have any more values. > > If you need the indirection provided by those it1 and it2, you need to > postpone the function

Re: list comprehension question

2009-05-01 Thread J Kenneth King
Chris Rebert writes: > On Thu, Apr 30, 2009 at 5:56 PM, Ross wrote: >> If I have a list of tuples a = [(1,2), (3,4), (5,6)], and I want to >> return a new list of each individual element in these tuples, I can do >> it with a nested for loop but when I try to do it using the list >> comprehensio

Passing a function as an argument from within the same class?

2009-05-01 Thread zealalot
So, I'm trying to come up with a way to pass a method (from the same class) as the default argument for another method in the same class. Unfortunately though, I keep getting "self not defined" errors since the class hasn't been read completely before it references itself. Is there a better way of

Re: where to start with

2009-05-01 Thread CTO
I'd add http://diveintopython.org/ to that list as you gain more experience with Python, or if you already know at least one language. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python servlet for Java applet ?

2009-05-01 Thread Linuxguy123
On Thu, 2009-04-30 at 14:06 +0200, Piet van Oostrum wrote: > Well, for a start, in the Python world the word 'servlet' isn't used > much. So I assume it comes from your Java legacy and you actually mean > 'any server-side python script' (in webware they use the term > 'servlet', however). I ag

Re: Passing a function as an argument from within the same class?

2009-05-01 Thread bearophileHUGS
Zealalot, probably there are some ways to do that, but a simple one is the following (not tested): def function2(self, passed_function=None): if passed_function is None: passed_function = self.doNothing ... Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: What do you think of ShowMeDo

2009-05-01 Thread Peter Pearson
On Fri, 1 May 2009 07:53:35 +1000, Paul Hemans wrote: [snip] > them as they have been recorded in the anals of the web, however I .^ That's the second time in this thread. The first might have been deliberate gross wordplay, but now it's time for some

Re: Passing a function as an argument from within the same class?

2009-05-01 Thread CTO
Make doNothing a classmethod. class SomeClass: @classmethod def doNothing(cls): pass def function1(self): print "Running function 1" def function2(self, passedFunction=SomeClass.doNothing): print "Running passed function" passedFunction() someObj

Re: How to measure the memory cost in Python?

2009-05-01 Thread CTO
Not OP, but I'd actually like to know if there's an answer to this one that doesn't involve platform-specific tools. -- http://mail.python.org/mailman/listinfo/python-list

Re: What do you think of ShowMeDo

2009-05-01 Thread Grant Edwards
On 2009-05-01, Peter Pearson wrote: > On Fri, 1 May 2009 07:53:35 +1000, Paul Hemans wrote: > [snip] >> them as they have been recorded in the anals of the web, however I >.^ > > That's the second time in this thread. The first might have been > delib

Re: How to measure the memory cost in Python?

2009-05-01 Thread Chris Rebert
On Fri, May 1, 2009 at 7:54 AM, CTO wrote: > Not OP, but I'd actually like to know if there's an answer to this one > that doesn't involve platform-specific tools. sys.getsizeof() [a suggested solution] isn't platform-specific. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org

Re: urllib2 and threading

2009-05-01 Thread robean
Thanks for your reply. Obviously you make several good points about Beautiful Soup and Queue. But here's the problem: even if I do nothing whatsoever with the threads beyond just visiting the urls with urllib2, the program chokes. If I replace else: ulock.acquire() print page.geturl() #

Re: Passing a function as an argument from within the same class?

2009-05-01 Thread zealalot
On May 1, 10:50 am, CTO wrote: > Make doNothing a classmethod. > > class SomeClass: > >     @classmethod >     def doNothing(cls): >         pass > >     def function1(self): >         print "Running function 1" > >     def function2(self, passedFunction=SomeClass.doNothing): >         print "Runn

Re: where to start with

2009-05-01 Thread Kyle Terry
On Fri, May 1, 2009 at 7:38 AM, CTO wrote: > I'd add http://diveintopython.org/ to that list as you gain more > experience with Python, or if you already know at least one language. Wasn't diveintopython in his list? > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://ma

Re: Passing a function as an argument from within the same class?

2009-05-01 Thread Peter Otten
CTO wrote: > Make doNothing a classmethod. > > class SomeClass: > > @classmethod > def doNothing(cls): > pass > > def function1(self): > print "Running function 1" > > def function2(self, passedFunction=SomeClass.doNothing): > print "Running passed funct

Re: list comprehension question

2009-05-01 Thread Emile van Sebille
On 5/1/2009 7:31 AM J Kenneth King said... Chris Rebert writes: b = [] for pair in a: for item in pair: b.append(item) This is much more clear than a nested comprehension. I love comprehensions, but abusing them can lead to really dense and difficult to read code. I disagree on

Re: string processing question

2009-05-01 Thread Scott David Daniels
Kurt Mueller wrote: Scott David Daniels schrieb: To discover what is happening, try something like: python -c 'for a in "ä", unicode("ä"): print len(a), a' I suspect that in your encoding, "ä" is two bytes long, and in unicode it is converted to to a single character. :> python -c 'for a

Re: list comprehension question

2009-05-01 Thread Arnaud Delobelle
Emile van Sebille writes: > On 5/1/2009 7:31 AM J Kenneth King said... >> Chris Rebert writes: >>> b = [] >>> for pair in a: >>> for item in pair: >>> b.append(item) >> >> This is much more clear than a nested comprehension. >> >> I love comprehensions, but abusing them can lead to r

Re: [Python-Dev] .pth files are evil

2009-05-01 Thread Chris Withers
M.-A. Lemburg wrote: """ If the package really requires adding one or more directories on sys.path (e.g. because it has not yet been structured to support dotted-name import), a "path configuration file" named package.pth can be placed in either the site-python or site-packages directory. ... A t

object query assigned variable name?

2009-05-01 Thread warpcat
I've passed this around some other groups, and I'm being told "probably not possible". But I thought I'd try here as well :) I *did* search first, and found several similar threads, but they quickly tangented into other specifics of the language that were a bit over my head :) At any rate, here

Re: [Python-Dev] PEP 382: little help for stupid people?

2009-05-01 Thread Chris Withers
M.-A. Lemburg wrote: The much more common use case is that of wanting to have a base package installation which optional add-ons that live in the same logical package namespace. The PEP provides a way to solve this use case by giving both developers and users a standard at hand which they can fo

Re: [Python-Dev] PEP 382: Namespace Packages

2009-05-01 Thread Chris Withers
P.J. Eby wrote: At 06:15 PM 4/15/2009 +0200, M.-A. Lemburg wrote: The much more common use case is that of wanting to have a base package installation which optional add-ons that live in the same logical package namespace. Please see the large number of Zope and PEAK distributions on PyPI as

Re: Passing a function as an argument from within the same class?

2009-05-01 Thread Scott David Daniels
zealalot wrote: On May 1, 10:50 am, CTO wrote: Make doNothing a classmethod. class SomeClass: @classmethod def doNothing(cls): ... def function2(self, passedFunction=SomeClass.doNothing): print "Running passed function" passedFunction() ... It's not surprising,

Re: urllib2 and threading

2009-05-01 Thread Stefan Behnel
robean wrote: > I am writing a program that involves visiting several hundred webpages > and extracting specific information from the contents. I've written a > modest 'test' example here that uses a multi-threaded approach to > reach the urls with urllib2. The actual program will involve fairly >

Re: list comprehension question

2009-05-01 Thread Shane Geiger
from goopy.functional import flatten # http://sourceforge.net/projects/goog-goopy/ b = [(1,2), (3,4), (5,6)] print flatten(b) #from goopy.functional import flatten # http://sourceforge.net/projects/goog-goopy/ def flatten(seq): """ Returns a list of the contents of seq with sublists and

Re: object query assigned variable name?

2009-05-01 Thread Scott David Daniels
warpcat wrote: I've passed this around some other groups, and I'm being told "probably not possible". But I thought I'd try here as well :) ... Given an object: class Spam(object): def __init__(self): # stuff I'd like it to print, when instanced, something like this:

Re: How to measure the memory cost in Python?

2009-05-01 Thread Jean
On May 1, 7:54 am, CTO wrote: > Not OP, but I'd actually like to know if there's an answer to this one > that doesn't involve platform-specific tools. Depending on what you need and the O/S you are using, this recipe may help That recipe also appe

Re: [Python-Dev] PEP 382: little help for stupid people?

2009-05-01 Thread Martin v. Löwis
> In either of the proposals on the table, what code would I write and > where to have a base package with a set of add-on packages? I don't quite understand the question. Why would you want to write code (except for the code that actually is in the packages)? PEP 382 is completely declarative -

Re: [Python-Dev] .pth files are evil

2009-05-01 Thread Scott David Daniels
Chris Withers wrote: M.-A. Lemburg wrote: """ If the package really requires adding one or more directories on sys.path (e.g. because it has not yet been structured to support dotted-name import), a "path configuration file" named package.pth can be placed in either the site-python or site-pac

Re: Multiprocessing Pool and functions with many arguments

2009-05-01 Thread Piet van Oostrum
> "psaff...@googlemail.com" (P) wrote: >P> I'm trying to get to grips with the multiprocessing module, having >P> only used ParallelPython before. >P> based on this example: >P> http://docs.python.org/library/multiprocessing.html#using-a-pool-of-workers >P> what happens if I want my "f" to

Re: object query assigned variable name?

2009-05-01 Thread Steven D'Aprano
On Fri, 01 May 2009 09:24:10 -0700, warpcat wrote: > I'd like it to print, when instanced, something like this: > s = Spam() > I’m assigned to s! > > But it seems prohibitively hard (based on my web and forum searches) for > an object to know what variable name is has been assigned to when

Re: [Python-Dev] PEP 382: little help for stupid people?

2009-05-01 Thread Chris Withers
Martin v. Löwis wrote: In either of the proposals on the table, what code would I write and where to have a base package with a set of add-on packages? I don't quite understand the question. Why would you want to write code (except for the code that actually is in the packages)? PEP 382 is com

Re: Re: list comprehension question

2009-05-01 Thread John Posner
Shane Geiger wrote: if type(el) == list or type(el) is tuple: A tiny improvement: if type(el) in (list, tuple): -- http://mail.python.org/mailman/listinfo/python-list

Re: object query assigned variable name?

2009-05-01 Thread David Robinow
On Fri, May 1, 2009 at 12:24 PM, warpcat wrote: > I've passed this around some other groups, and I'm being told > "probably not possible".  But I thought I'd try here as well :)   I > *did* search first, and found several similar threads, but they > quickly tangented into other specifics of the la

Re: Passing a function as an argument from within the same class?

2009-05-01 Thread Steven D'Aprano
On Fri, 01 May 2009 08:11:01 -0700, zealalot wrote: > On May 1, 10:50 am, CTO wrote: >> Make doNothing a classmethod. >> >> class SomeClass: >> >>     @classmethod >>     def doNothing(cls): >>         pass >> >>     def function1(self): >>         print "Running function 1" >> >>     def functio

Re: object query assigned variable name?

2009-05-01 Thread AKEric
On May 1, 9:48 am, Steven D'Aprano wrote: > On Fri, 01 May 2009 09:24:10 -0700, warpcat wrote: > > I'd like it to print, when instanced, something like this: > > s = Spam() > > I’m assigned to s! > > > But it seems prohibitively hard (based on my web and forum searches) for > > an object to k

Re: Passing a function as an argument from within the same class?

2009-05-01 Thread Steven D'Aprano
On Fri, 01 May 2009 07:35:40 -0700, zealalot wrote: > So, I'm trying to come up with a way to pass a method (from the same > class) as the default argument for another method in the same class. > Unfortunately though, I keep getting "self not defined" errors since the > class hasn't been read comp

Re: Importing modules

2009-05-01 Thread norseman
Gabriel Genellina wrote: En Thu, 30 Apr 2009 14:33:38 -0300, Jim Carlock escribió: I'm messing around with a program right at the moment. It ends up as two applications, one runs as a server and one as a client which presents a Window. It almost works, so I need to work through it to work out i

Re: object query assigned variable name?

2009-05-01 Thread AKEric
On May 1, 10:03 am, David Robinow wrote: > On Fri, May 1, 2009 at 12:24 PM, warpcat wrote: > > I've passed this around some other groups, and I'm being told > > "probably not possible".  But I thought I'd try here as well :)   I > > *did* search first, and found several similar threads, but they

Re: Passing a function as an argument from within the same class?

2009-05-01 Thread CTO
> Careful, bearophiles' answer remains the best one. > > The only reason your example worked is that you had already had > SomeClass defined (probably from a previous experiment). Scott is correct, and if bearophile and I ever give you conflicting advice, take bearophile's. A (corrected) bit of c

Re: object query assigned variable name?

2009-05-01 Thread Steven D'Aprano
On Fri, 01 May 2009 13:03:56 -0400, David Robinow wrote: > Others have explained to you that this is not possible. I'll just point > out that your method for learning the language is not optimal. If you > had gotten a recipe to do what you asked, how would it help you write > better programs? Exa

Re: list comprehension question

2009-05-01 Thread Emile van Sebille
On 5/1/2009 9:19 AM Arnaud Delobelle said... Emile van Sebille writes: On 5/1/2009 7:31 AM J Kenneth King said... I love comprehensions, but abusing them can lead to really dense and difficult to read code. I disagree on dense and difficult, although I'll leave open the question of abuse. b

Re: [Python-Dev] PEP 382: little help for stupid people?

2009-05-01 Thread Martin v. Löwis
>>> In either of the proposals on the table, what code would I write and >>> where to have a base package with a set of add-on packages? >> >> I don't quite understand the question. Why would you want to write code >> (except for the code that actually is in the packages)? >> >> PEP 382 is complete

ctypes: reference of a struct member?

2009-05-01 Thread ma
If I have this struct in C: struct spam { int ham; char foo; }; if I have this declaration: struct spam s_; If I wanted to pass a reference to a function of s_'s foo character, I can do something like this: somefunc(&s_.foo) How do I do the same thing in ctypes? ctypes.addressof(s_) +

Re: list comprehension question

2009-05-01 Thread Arnaud Delobelle
Emile van Sebille writes: > On 5/1/2009 9:19 AM Arnaud Delobelle said... >> Emile van Sebille writes: >>> On 5/1/2009 7:31 AM J Kenneth King said... I love comprehensions, but abusing them can lead to really dense and difficult to read code. >>> I disagree on dense and difficult, altho

Re: How to measure the memory cost in Python?

2009-05-01 Thread CTO
> sys.getsizeof() [a suggested solution] isn't platform-specific. So, to answer the OP's question, you'd just do something like def get_totalsize(obj): total_size = sys.getsizeof(obj) for value in vars(obj).values(): try: total_size += get_total_size(value)

Re: urllib2 and threading

2009-05-01 Thread shailen . tuli
For better performance, lxml easily outperforms Beautiful Soup. For what its worth, the code runs fine if you switch from urllib2 to urllib (different exceptions are raised, obviously). I have no experience using urllib2 in a threaded environment, so I'm not sure why it breaks; urllib does OK, tho

Re: ctypes: reference of a struct member?

2009-05-01 Thread CTO
ctypes.byref() -- http://mail.python.org/mailman/listinfo/python-list

Re: object query assigned variable name?

2009-05-01 Thread Nick Craig-Wood
warpcat wrote: > I've passed this around some other groups, and I'm being told > "probably not possible". But I thought I'd try here as well :) I > *did* search first, and found several similar threads, but they > quickly tangented into other specifics of the language that were a bit > ove

Re: Passing a function as an argument from within the same class?

2009-05-01 Thread Dave Angel
zealalot wrote: On May 1, 10:50 am, CTO wrote: Make doNothing a classmethod. class SomeClass: @classmethod def doNothing(cls): pass def function1(self): print "Running function 1" def function2(self, passedFunction=meClass.doNothing): print "Runnin

Re: ctypes: reference of a struct member?

2009-05-01 Thread ma
ctypes.byref() does not work for struct members. Try it out. class s(ctypes.Structure): _fields_ = [('x',ctypes.c_int)] a = s() ctypes.byref(a.x) //this won't work. On Fri, May 1, 2009 at 2:28 PM, CTO wrote: > ctypes.byref() > > -- > http://mail.python.org/mailman/listinfo/python-list > --

Re: list comprehension question

2009-05-01 Thread Scott David Daniels
John Posner wrote: Shane Geiger wrote: if type(el) == list or type(el) is tuple: A tiny improvement: if type(el) in (list, tuple): or (even better) if isinstance(el, (list, tuple)) However, it is my contention that you shouldn't be flattening by type -- you should know where,

Re: don't understand namespaces...

2009-05-01 Thread norseman
Simon Forman wrote: On Apr 30, 10:11 am, Lawrence Hanser wrote: Dear Pythoners, I think I do not yet have a good understanding of namespaces. Here is what I have in broad outline form: import Tkinter Class App(Frame) define two frames, buttons in o

Re: fcntl and siginfo_t in python

2009-05-01 Thread ma
According to man signal, "The default action for an unhandled real-time signal is to terminate the receiving process." This means that my registered callback and sigaction does not work. I think the only solution would be to try this with a C-extension. Has anyone had any experience with this befo

Re: Passing a function as an argument from within the same class?

2009-05-01 Thread Scott David Daniels
Steven D'Aprano wrote: On Fri, 01 May 2009 07:35:40 -0700, zealalot wrote: So, I'm trying to come up with a way to pass a method (from the same class) as the default argument for another method in the same class My first instinct is to say "Don't do that!", but let's see if there's a way

Re: [Python-Dev] .pth files are evil

2009-05-01 Thread Tim Golden
Chris Withers wrote: I'll say! I think .pth files are absolute evil and I wish they could just be banned. +1 on anything that makes them closer to going away or reduces the possibility of yet another similar feature from hurting the comprehensibility of a python setup. I've seen this view e

Re: wxPython having trouble with frame objects

2009-05-01 Thread Dave Angel
Soumen banerjee wrote: Hello, The code works almost perfectly. I was able to correct some small things, and get it to work brilliantly. I would like to thank you for your dedicated help. My understanding of the matter here has improved by a lot due to your kind help. I will further work on your s

Re: How to measure the memory cost in Python?

2009-05-01 Thread Jean
On May 1, 10:56 am, CTO wrote: > > sys.getsizeof() [a suggested solution] isn't platform-specific. > > So, to answer the OP's question, you'd just do something like > > def get_totalsize(obj): >         total_size = sys.getsizeof(obj) >         for value in vars(obj).values(): >                 tr

Question about the wording in the python documents.

2009-05-01 Thread grocery_stocker
At the following url... http://docs.python.org/library/urllib2.html They have the following... "urllib2.urlopen(url[, data][, timeout]) Open the URL url, which can be either a string or a Request object" I don't get how urllib2.urlopen() can take a Request object. When I do the following..

[ANN] Python testing client for Second Life virtual world

2009-05-01 Thread Lawson English
If anyone is curious, I'm working on a GUI shell for the python second life client, pyogp. Temp home for pyogp intro: https://wiki.secondlife.com/wiki/Pyogp/Client_Lib Basically the [first] plan is to have a GUI wrapper around the sample code with a batch file option, and to allow multiple ava

Profiling gives very different predictions of best algorithm

2009-05-01 Thread Rick Muller
I'm the main programmer for the PyQuante package, a quantum chemistry package in Python. I'm trying to speed up one of my rate determining steps. Essentially, I have to decide between two algorithms: 1. Packed means that I compute N**4/8 integrals, and then do a bunch of indexing operations to unp

Re: Profiling gives very different predictions of best algorithm

2009-05-01 Thread Brian
quantum chemistry sounds complicated. that means any advice i can give you makes me a genius! just kidding. i've heard through the grapevine that reentrant functions mess up profilers. On Fri, May 1, 2009 at 2:54 PM, Rick Muller wrote: > I'm the main programmer for the PyQuante package, a quantu

Re: Importing modules

2009-05-01 Thread Terry Reedy
norseman wrote: OH - something you mentioned that didn't seem to be addressed. import - load a complete library from - obtain specific 'function'(s) from a library from can also be used to get a specific module from a package If you 'import pack.mod', then you have to write 'pack.mod.ob' to

  1   2   >