Symbols as parameters?

2010-01-20 Thread Martin Drautzburg
Hello all, When passing parameters to a function, you sometimes need a paramter which can only assume certain values, e.g. def move (direction): ... If direction can only be "up", "down", "left" or "right", you can solve this by passing strings, but this is not quite to th

Re: Sorted dictionary

2010-01-20 Thread Chris Rebert
On Wed, Jan 20, 2010 at 5:50 PM, Steven D'Aprano wrote: > On Thu, 21 Jan 2010 02:02:02 +0100, Jan Kaliszewski wrote: > >> Hello, >> >> Inspired by some my needs as well as some discussions in the net, I've >> implemented a sorted dictionary (i.e. a dict that returns keys, values >> and items alway

Re: why the super class can access the subclass's attribute

2010-01-20 Thread Chris Rebert
On Wed, Jan 20, 2010 at 8:56 PM, yousay wrote: > I have sees aprogram like this ,i confusing why super class can access > the subclass's attribute To make this easy to understand, I'm going to ***drastically*** oversimplify. With that disclaimer out of the way... When you access an instance attr

Re: counting lines of code

2010-01-20 Thread Michele Simionato
On Jan 21, 8:12 am, Ben Finney wrote: > Michele Simionato writes: > > I need a small utility to count the lines of Python code in a > > directory, traversing subdirectories and ignoring comments and > > docstrings. I am sure there is already something doing that, what do > > you suggest? > > Any

Re: counting lines of code

2010-01-20 Thread Michele Simionato
I did not known about cloc, it does more that I need, but it looks cool (it is perl and not Python, by who cares? ;) Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list

Re: counting lines of code

2010-01-20 Thread Ben Finney
Michele Simionato writes: > I need a small utility to count the lines of Python code in a > directory, traversing subdirectories and ignoring comments and > docstrings. I am sure there is already something doing that, what do > you suggest? Any of the static code checkers (‘pylint’, ‘pyflakes’,

Re: counting lines of code

2010-01-20 Thread Mark Hammond
On 21/01/2010 5:51 PM, Michele Simionato wrote: I need a small utility to count the lines of Python code in a directory, traversing subdirectories and ignoring comments and docstrings. I am sure there is already something doing that, what do you suggest? I suggest typing your subject line into

Re: Sorted dictionary

2010-01-20 Thread Steven D'Aprano
On Wed, 20 Jan 2010 22:21:22 -0800, Dennis Lee Bieber wrote: > On Thu, 21 Jan 2010 02:02:02 +0100, "Jan Kaliszewski" > declaimed the following in > gmane.comp.python.general: > >> Hello, >> >> Inspired by some my needs as well as some discussions in the net, I've >> implemented a sorted diction

counting lines of code

2010-01-20 Thread Michele Simionato
I need a small utility to count the lines of Python code in a directory, traversing subdirectories and ignoring comments and docstrings. I am sure there is already something doing that, what do you suggest? TIA, Michele Simionato -- http://mail.python.org/mailman/listinfo

Re: py2exe and pydocs. Downloads?

2010-01-20 Thread Gabriel Genellina
En Wed, 20 Jan 2010 21:22:19 -0300, Gib Bogle escribió: Gabriel Genellina wrote: c:\temp>python -m pydoc sys Help on built-in module sys: [...same info...] When I do this I get: No module named tempfile You found a bug. Looks like it depends on the environment, or what packages are i

Re: Inheriting methods but over-riding docstrings

2010-01-20 Thread Michele Simionato
On Jan 21, 12:09 am, "Gabriel Genellina" wrote: > This is basically the same technique as in   > but there is   > a difference: you clone the function object *and* the code object it is   > based on. As I understand it, code objects are

Re: Interesting Problem

2010-01-20 Thread alex23
Victor Subervi wrote: > I think I finally have an interesting problem for y'all. I need to import a > script from a lower dir, forcing me to change dirs: I'm surprised that no one has yet mentioned packages. Suppose you have the following folder layout and you stick an empty __init__.py in each s

Re: Create object name from string value?

2010-01-20 Thread Steven D'Aprano
On Wed, 20 Jan 2010 19:02:49 -0800, Gnarlodious wrote: > I want to declare several objects from names in a list: > > objects=['object1', 'object2', 'object3', 'object4'] for objectName in > objects: > objectName=classname() That's the wrong way to handle the problem. Named objects are onl

why the super class can access the subclass's attribute

2010-01-20 Thread yousay
I have sees aprogram like this ,i confusing why super class can access the subclass's attribute ,this is the program,thanks in advance: class MyThread(threading.Thread): def join(self): super(MyThread,self).join() return self.result class Worker(MyThread): import random

Re: Create object name from string value?

2010-01-20 Thread Gnarlodious
On Jan 20, 8:31 pm, Ben Finney wrote: > Since (I presume) you are a newcomer to Python, it's best to learn the > common style http://www.python.org/dev/peps/pep-0008/>. Thanks for that. > This is almost certainly better done with a dictionary. Like so:: > >     object_names = ['object1', 'object2

Re: Create object name from string value?

2010-01-20 Thread Ben Finney
Gnarlodious writes: > I want to declare several objects from names in a list: > > objects=['object1', 'object2', 'object3', 'object4'] > for objectName in objects: > objectName=classname() Since (I presume) you are a newcomer to Python, it's best to learn the common style http://www.python

Create object name from string value?

2010-01-20 Thread Gnarlodious
I want to declare several objects from names in a list: objects=['object1', 'object2', 'object3', 'object4'] for objectName in objects: objectName=classname() That fails, and so do these: exec(objectName)=classname() eval(objectName)=classname() So how to make an object whose name is th

Re: Py 3: How to switch application to Unicode strings?

2010-01-20 Thread Gnarlodious
Thanks for the help, but I am going to skip this problem because I don't need Unicode characters in a script anyway. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: Sorted dictionary

2010-01-20 Thread Steven D'Aprano
On Thu, 21 Jan 2010 02:02:02 +0100, Jan Kaliszewski wrote: > Hello, > > Inspired by some my needs as well as some discussions in the net, I've > implemented a sorted dictionary (i.e. a dict that returns keys, values > and items always sorted by keys): > > http://code.activestate.com/recipes/5769

Re: * operator in python tutorial

2010-01-20 Thread Gringo
On 1/20/2010 12:38, ben wrote: > Hello, > > I am following through the python tutorial which gets to a line that > uses the * operator with zip(). I searched and searched but could find > no information on the operator or how to use it in general. The > example from the tut is as follows: x =

Re: Using jython to call python procedures/methods

2010-01-20 Thread bobicanprogram
On Jan 20, 10:32 am, KB wrote: > Hi there, > > I have an application that only publishes a Java API. I can use jython > to access java classes, but jython currently (to the best of my > knowledge) does not support numpy/scipy. > > Ideally I would like to have jython call a "native" python routine

Sorted dictionary

2010-01-20 Thread Jan Kaliszewski
Hello, Inspired by some my needs as well as some discussions in the net, I've implemented a sorted dictionary (i.e. a dict that returns keys, values and items always sorted by keys): http://code.activestate.com/recipes/576998/ Maybe it'll appear to be useful for somebody... And I'm curious

Re: py2exe and pydocs. Downloads?

2010-01-20 Thread Gib Bogle
Gabriel Genellina wrote: c:\temp>python -m pydoc sys Help on built-in module sys: [...same info...] When I do this I get: No module named tempfile -- http://mail.python.org/mailman/listinfo/python-list

Re: installing psycopg2-2.0.13 with python3.1

2010-01-20 Thread Gabriel Genellina
En Wed, 20 Jan 2010 19:45:44 -0300, Iain Barnett escribió: Would anyone know if it's possible to install psycopg2-2.0.13 with python3.1.1 (or similar)?I can install it with python2.6 with no problems, but obviously I'd prefer to use the latest version. My system is OSX10.6, and I'm new t

Re: multiprocessing problems

2010-01-20 Thread Nils Ruettershoff
Hi, Adam Tauno Williams wrote: [...] Here's the guts of my latest incarnation. def ProcessBatch(files): p = [] for file in files: p.append(Process(target=ProcessFile,args=file)) for x in p: x.start() for x in p: x.join() p = [] return Now, the fun

Re: installing psycopg2-2.0.13 with python3.1

2010-01-20 Thread Philip Semanchuk
On Jan 20, 2010, at 5:45 PM, Iain Barnett wrote: Hi, Would anyone know if it's possible to install psycopg2-2.0.13 with python3.1.1 (or similar)? When I try I get the following $ sudo python setup.py install Password: File "setup.py", line 233 except Warning, w: ^ Synt

Re: multiprocessing problems

2010-01-20 Thread Nils Ruettershoff
Hi Doxa, DoxaLogos wrote: [...] I found out my problems. One thing I did was followed the test queue example in the documentation, but the biggest problem turned out to be a pool instantiated globally in my script was causing most of the endless process spawn, even with the "if __name__ == "__m

Re: html code generation

2010-01-20 Thread Jon Clements
On Jan 20, 10:03 pm, "D'Arcy J.M. Cain" wrote: > On Wed, 20 Jan 2010 21:03:10 + > > George Trojan wrote: > > I need an advice on table generation. The table is essentially a fifo, > > containing about 200 rows. The rows are inserted every few minutes or > > so. The simplest solution is to sto

Re: Inheriting methods but over-riding docstrings

2010-01-20 Thread Gabriel Genellina
En Tue, 19 Jan 2010 08:44:09 -0300, Michele Simionato escribió: On Jan 16, 6:55 pm, Steven D'Aprano wrote: I have a series of subclasses that inherit methods from a base class, but I'd like them to have their own individual docstrings. from types import FunctionType, CodeType def newfu

installing psycopg2-2.0.13 with python3.1

2010-01-20 Thread Iain Barnett
Hi, Would anyone know if it's possible to install psycopg2-2.0.13 with python3.1.1 (or similar)? When I try I get the following $ sudo python setup.py install Password: File "setup.py", line 233 except Warning, w:

Re: Object Integer mapping

2010-01-20 Thread NighterNet
On Jan 20, 9:43 am, Robert Kern wrote: > On 2010-01-20 11:18 AM, Richard Thomas wrote: > > > > > On Jan 20, 4:43 pm, NighterNet  wrote: > >> Need help on python version 3.1.x. I can't seem to know what going on > >> a bit. The code that I check that the hash is different every time. Is > >> there

Re: html code generation

2010-01-20 Thread Chris Colbert
ah ok, i misread your post. Store each 'junk' as an item in the deque. the idea is the same though. On Wed, Jan 20, 2010 at 4:55 PM, Chris Colbert wrote: > > > On Wed, Jan 20, 2010 at 4:52 PM, Chris Colbert wrote: > >> use a deque with a 'junk' as each element >> >> http://docs.python.org/librar

Re: html code generation

2010-01-20 Thread D'Arcy J.M. Cain
On Wed, 20 Jan 2010 21:03:10 + George Trojan wrote: > I need an advice on table generation. The table is essentially a fifo, > containing about 200 rows. The rows are inserted every few minutes or > so. The simplest solution is to store row data per line and write > directly html code: > li

Re: html code generation

2010-01-20 Thread Chris Colbert
On Wed, Jan 20, 2010 at 4:52 PM, Chris Colbert wrote: > use a deque with a 'junk' as each element > > http://docs.python.org/library/collections.html > > On Wed, Jan 20, 2010 at 4:03 PM, George Trojan wrote: > >> I need an advice on table generation. The table is essentially a fifo, >> containing

Re: html code generation

2010-01-20 Thread Chris Colbert
use a deque with a 'junk' as each element http://docs.python.org/library/collections.html On Wed, Jan 20, 2010 at 4:03 PM, George Trojan wrote: > I need an advice on table generation. The table is essentially a fifo, > containing about 200 rows. The rows are inserted every few minutes or so. > T

Re: Best way to convert sequence of bytes to long integer

2010-01-20 Thread Steven D'Aprano
On Wed, 20 Jan 2010 19:27:34 +0100, Alf P. Steinbach wrote: > * Mark Dickinson: >> On Jan 20, 7:36 am, Steven D'Aprano > cybersource.com.au> wrote: >>> I have a byte string (Python 2.x string), e.g.: >>> >>> s = "g%$f yg\n1\05" >>> assert len(s) == 10 >>> >>> I wish to convert it to a long integer

html code generation

2010-01-20 Thread George Trojan
I need an advice on table generation. The table is essentially a fifo, containing about 200 rows. The rows are inserted every few minutes or so. The simplest solution is to store row data per line and write directly html code: line = "value1value2>... " each run of the program would read the pr

Re: Using jython to call python procedures/methods

2010-01-20 Thread M.-A. Lemburg
KB wrote: > Hi there, > > I have an application that only publishes a Java API. I can use jython > to access java classes, but jython currently (to the best of my > knowledge) does not support numpy/scipy. > > Ideally I would like to have jython call a "native" python routine > where I have the n

Re: What is a list compression in Python?

2010-01-20 Thread Luis M . González
On Jan 18, 1:07 pm, Kit wrote: > Hello Everyone, I am not sure if I have posted this question in a > correct board. Can anyone please teach me: > > What is a list compression in Python? > > Would you mind give me some list compression examples? > > Thanks & really appreciate that. > Kit It's also

Re: Interesting Problem

2010-01-20 Thread M.-A. Lemburg
Victor Subervi wrote: > Hi; > I think I finally have an interesting problem for y'all. I need to import a > script from a lower dir, forcing me to change dirs: > > cwd = os.getcwd() > os.chdir('%s/..' % cwd) > sys.path.append(os.getcwd()) > from templateFrame import top, bottom > os.chdir(cwd) I

Re: * operator in python tutorial

2010-01-20 Thread ben
I missed it because I skipped to the explanation of zip. I hit the back arrow and went on and saw the link to "Unpacking Argument Lists" which explained what I needed to know. Thanks. -- http://mail.python.org/mailman/listinfo/python-list

* operator in python tutorial

2010-01-20 Thread ben
Hello, I am following through the python tutorial which gets to a line that uses the * operator with zip(). I searched and searched but could find no information on the operator or how to use it in general. The example from the tut is as follows: >>> x = [1, 2, 3] >>> y = [4, 5, 6] >>> zipped = zi

Re: Best way to convert sequence of bytes to long integer

2010-01-20 Thread Alf P. Steinbach
* Mark Dickinson: On Jan 20, 7:36 am, Steven D'Aprano wrote: I have a byte string (Python 2.x string), e.g.: s = "g%$f yg\n1\05" assert len(s) == 10 I wish to convert it to a long integer, treating it as base-256. By the way, are you willing to divulge what you're using this functionality f

Re: Interesting Problem

2010-01-20 Thread MRAB
James Matthews wrote: Also as a side point... It's best to anonymize the code as best you can so people cannot attach your code to your site (IP theft and security risk) [snip] Security risk, yes; IP theft, not so much. ;-) -- http://mail.python.org/mailman/listinfo/python-list

Re: Object Integer mapping

2010-01-20 Thread Robert Kern
On 2010-01-20 11:18 AM, Richard Thomas wrote: On Jan 20, 4:43 pm, NighterNet wrote: Need help on python version 3.1.x. I can't seem to know what going on a bit. The code that I check that the hash is different every time. Is there a way to make the hash the same? I using as to check the class i

Re: Object Integer mapping

2010-01-20 Thread Richard Thomas
On Jan 20, 4:43 pm, NighterNet wrote: > Need help on python version 3.1.x. I can't seem to know what going on > a bit. The code that I check that the hash is different every time. Is > there a way to make the hash the same? I using as to check the class > is the same variables but if it different

Re: Interesting Problem

2010-01-20 Thread Victor Subervi
On Wed, Jan 20, 2010 at 12:30 PM, Stephen Hansen wrote: > On Wed, Jan 20, 2010 at 7:19 AM, Victor Subervi > wrote: > >> Hi; >> I think I finally have an interesting problem for y'all. I need to import >> a script from a lower dir, forcing me to change dirs: >> > > Don't do that. If you must, then

Re: Interesting Problem

2010-01-20 Thread James Matthews
Also as a side point... It's best to anonymize the code as best you can so people cannot attach your code to your site (IP theft and security risk) On Wed, Jan 20, 2010 at 8:38 AM, MRAB wrote: > Victor Subervi wrote: > >> Hi; >> I think I finally have an interesting problem for y'all. I need to

Re: Interesting Problem

2010-01-20 Thread Gary Herron
Victor Subervi wrote: Hi; I think I finally have an interesting problem for y'all. I need to import a script from a lower dir, forcing me to change dirs: Wait a moment... Your assumption that you need to change directories is invalid. (And that means everything you do below this point unnec

Re: Using jython to call python procedures/methods

2010-01-20 Thread KB
Hmmm, XML is an interesting angle... I'll noodle it... -- http://mail.python.org/mailman/listinfo/python-list

Object Integer mapping

2010-01-20 Thread NighterNet
Need help on python version 3.1.x. I can't seem to know what going on a bit. The code that I check that the hash is different every time. Is there a way to make the hash the same? I using as to check the class is the same variables but if it different variable in the class that it add to the array

Re: Interesting Problem

2010-01-20 Thread MRAB
Victor Subervi wrote: Hi; I think I finally have an interesting problem for y'all. I need to import a script from a lower dir, forcing me to change dirs: cwd = os.getcwd() os.chdir('%s/..' % cwd) sys.path.append(os.getcwd()) from templateFrame import top, bottom os.chdir(cwd) There's no need

Re: Interesting Problem

2010-01-20 Thread Stephen Hansen
On Wed, Jan 20, 2010 at 7:19 AM, Victor Subervi wrote: > Hi; > I think I finally have an interesting problem for y'all. I need to import a > script from a lower dir, forcing me to change dirs: > Don't do that. If you must, then the correct way to do it is to adjust your sys.path and not change di

Re: multiprocessing problems

2010-01-20 Thread DoxaLogos
On Jan 19, 10:33 am, DoxaLogos wrote: > On Jan 19, 10:26 am, Adam Tauno Williams > wrote: > > > > > > I decided to play around with the multiprocessing module, and I'm > > > having some strange side effects that I can't explain.  It makes me > > > wonder if I'm just overlooking something obvious

Re: Using jython to call python procedures/methods

2010-01-20 Thread Kurt Smith
On Wed, Jan 20, 2010 at 9:32 AM, KB wrote: > Hi there, > > I have an application that only publishes a Java API. I can use jython > to access java classes, but jython currently (to the best of my > knowledge) does not support numpy/scipy. > > Ideally I would like to have jython call a "native" pyt

Re: turtle, ipython, and pylab don't mix

2010-01-20 Thread Robert Kern
On 2010-01-20 08:40 AM, Brian Blais wrote: Hello, I am noticing a hard crash of the ipython interpreter, with the pylab option, with the turtle module. I am on Win XP, Enthought Edition 6.0.0 which uses Python 2.6. I can't reproduce it without the pylab option, nor on the Mac (with an earlier En

turtle, ipython, and pylab don't mix

2010-01-20 Thread Brian Blais
Hello, I am noticing a hard crash of the ipython interpreter, with the pylab option, with the turtle module. I am on Win XP, Enthought Edition 6.0.0 which uses Python 2.6. I can't reproduce it without the pylab option, nor on the Mac (with an earlier Enthought Edition). The crash happe

Using jython to call python procedures/methods

2010-01-20 Thread KB
Hi there, I have an application that only publishes a Java API. I can use jython to access java classes, but jython currently (to the best of my knowledge) does not support numpy/scipy. Ideally I would like to have jython call a "native" python routine where I have the numpy/scipy procedures alre

Re: Changing var names

2010-01-20 Thread Victor Subervi
On Mon, Jan 18, 2010 at 10:10 AM, Jean-Michel Pichavant < jeanmic...@sequans.com> wrote: > Victor Subervi wrote: > >> On Fri, Jan 15, 2010 at 3:15 PM, Adam Tauno Williams < >> awill...@opengroupware.us > wrote: >> >>On Fri, 2010-01-15 at 13:27 -0400, Victor Su

Re: Something More Elegant

2010-01-20 Thread Victor Subervi
On Sun, Jan 17, 2010 at 5:36 PM, Dennis Lee Bieber wrote: >I don't think that would be efficient, considering that "the above" > entails what would be something like three or four courses all by > themselves (Database Analysis, Database Design, SQL [these three are > independent of any par

Interesting Problem

2010-01-20 Thread Victor Subervi
Hi; I think I finally have an interesting problem for y'all. I need to import a script from a lower dir, forcing me to change dirs: cwd = os.getcwd() os.chdir('%s/..' % cwd) sys.path.append(os.getcwd()) from templateFrame import top, bottom os.chdir(cwd) Because I've found I must do my form evalu

Re: examining an initial, pristine python3 shell session

2010-01-20 Thread Lie Ryan
On 01/20/10 22:59, Robert P. J. Day wrote: > then i might go a bit further to examine some of *those* objects. i > admit it might seem a bit dry, but i think it would be handy to have a > handle on what a clean shell session looks like before starting to > import things, then seeing how that impor

Re: examining an initial, pristine python3 shell session

2010-01-20 Thread Robert P. J. Day
On Wed, 20 Jan 2010, Alf P. Steinbach wrote: > * Robert P. J. Day: ... snip ... > > what other useful commands might i run immediately after > > starting a session whose output would be informative? i can > > certainly poke at some of those objects to see them in more > > detail. i'm just

Re: how to check if a module is importable?

2010-01-20 Thread Robert P. J. Day
On Thu, 21 Jan 2010, Lie Ryan wrote: > On 01/20/10 19:58, Robert P. J. Day wrote: > > > > finally getting back to clawing my way thru the python 3 book so > > probably a number of newbie questions coming up. first one -- can i > > check if a module is importable (equivalently, exists on sys.pat

Re: examining an initial, pristine python3 shell session

2010-01-20 Thread Alf P. Steinbach
* Alf P. Steinbach: * Robert P. J. Day: still working my way through "dive into python 3" and i've already been asked to give a newbie tutorial on it -- blind leading the blind, as it were. that should be hilarious. i'll be using python 3 and it occurred to me that it would be educational

Re: how to check if a module is importable?

2010-01-20 Thread Lie Ryan
On 01/20/10 19:58, Robert P. J. Day wrote: > > finally getting back to clawing my way thru the python 3 book so > probably a number of newbie questions coming up. first one -- can i > check if a module is importable (equivalently, exists on sys.path, i > assume) without trying to import it firs

Re: Best way to convert sequence of bytes to long integer

2010-01-20 Thread Mark Dickinson
On Jan 20, 7:36 am, Steven D'Aprano wrote: > I have a byte string (Python 2.x string), e.g.: > > s = "g%$f yg\n1\05" > assert len(s) == 10 > > I wish to convert it to a long integer, treating it as base-256. By the way, are you willing to divulge what you're using this functionality for? When tr

Re: examining an initial, pristine python3 shell session

2010-01-20 Thread Alf P. Steinbach
* Robert P. J. Day: still working my way through "dive into python 3" and i've already been asked to give a newbie tutorial on it -- blind leading the blind, as it were. that should be hilarious. i'll be using python 3 and it occurred to me that it would be educational (at least for me :-)

Re: twenty years ago Guido created Python

2010-01-20 Thread Stefan Behnel
n00m, 06.01.2010 01:25: > My mom a little girl wsas pursued by Germans alsatians dogs in a > forest > Germans just made a fun of it. > They screamead Zurich and laughed They laughed at her scare and you > now teach me. Now her hands tremble froom malntrination > She ate ate at WWII grass. And you t

Re: Best way to convert sequence of bytes to long integer

2010-01-20 Thread Paul Rubin
Steven D'Aprano writes: > s = "g%$f yg\n1\05" > Is this the best way, or have I missed some standard library function? It is really a shame that there is not a standard library function for this. I usually do it using hexadecimal conversion: d = int(s.encode('hex'), 16) -- http://mail.python

Re: substitution

2010-01-20 Thread Peter Otten
Wyrmskull wrote: > Your flowing pythonicity (if len(x):) gave me lots of inspiration. Actually, instead of if len(pairs): ... that should have been just if pairs: ... When I started writing the function I initially wanted to special-case len(pairs) == 1. The len() call is a superfluous lefto

examining an initial, pristine python3 shell session

2010-01-20 Thread Robert P. J. Day
still working my way through "dive into python 3" and i've already been asked to give a newbie tutorial on it -- blind leading the blind, as it were. that should be hilarious. i'll be using python 3 and it occurred to me that it would be educational (at least for me :-) to display what an in

Re: Performance of lists vs. list comprehensions

2010-01-20 Thread Dave Angel
Steven D'Aprano wrote: A million items is not a lot of data. Depending on the size of each object, that might be as little as 4 MB of data: L = ['' for _ in xrange(10**6)] sys.getsizeof(L) 4348732 Note that this sys.getsizeof() is only saying the size of the list, not the size

Memory usage problem of twisted server

2010-01-20 Thread Victor Lin
Hi, I encountered an increasing memory usage problem of my twisted server. I have posted a question on stackoverflow: http://stackoverflow.com/questions/2100192/how-to-find-the-source-of-increasing-memory-usage-of-a-twisted-server I have read the article "Improving Python's Memory Allocator" ( ht

Re: how to check if a module is importable?

2010-01-20 Thread Jean-Michel Pichavant
Robert P. J. Day wrote: finally getting back to clawing my way thru the python 3 book so probably a number of newbie questions coming up. first one -- can i check if a module is importable (equivalently, exists on sys.path, i assume) without trying to import it first? i can see that i can u

Re: setattr() oddness

2010-01-20 Thread M.-A. Lemburg
Dieter Maurer wrote: > Steven D'Aprano writes on 18 Jan 2010 > 06:47:59 GMT: >> On Mon, 18 Jan 2010 07:25:58 +0100, Dieter Maurer wrote: >> >>> Lie Ryan writes on Sat, 16 Jan 2010 19:37:29 +1100: On 01/16/10 10:10, Sean DiZazzo wrote: > Interesting. I can understand the "would take tim

Re: Best way to convert sequence of bytes to long integer

2010-01-20 Thread Mark Dickinson
On Jan 20, 7:36 am, Steven D'Aprano wrote: > I have a byte string (Python 2.x string), e.g.: > > s = "g%$f yg\n1\05" > assert len(s) == 10 > > I wish to convert it to a long integer, treating it as base-256. Not that it helps you right now, but provided someone finds the time, there should be an

how to check if a module is importable?

2010-01-20 Thread Robert P. J. Day
finally getting back to clawing my way thru the python 3 book so probably a number of newbie questions coming up. first one -- can i check if a module is importable (equivalently, exists on sys.path, i assume) without trying to import it first? i can see that i can use try/except and just ru

Re: Best way to convert sequence of bytes to long integer

2010-01-20 Thread Peter Otten
Steven D'Aprano wrote: > I have a byte string (Python 2.x string), e.g.: > > s = "g%$f yg\n1\05" > assert len(s) == 10 > > I wish to convert it to a long integer, treating it as base-256. > Currently I'm using: > > def makelong(s): > n = 0 > for c in s: > n *= 256 > n +=

Re: Performance of lists vs. list comprehensions

2010-01-20 Thread Alf P. Steinbach
* Steven D'Aprano: On Wed, 20 Jan 2010 05:25:22 +0100, Alf P. Steinbach wrote: * Steven D'Aprano: On Tue, 19 Jan 2010 16:20:42 -0500, Gerald Britton wrote: That's surprising. I wouldn't implement it that way at all. I'd use a dynamically-expanding buffer as I suggested. That way you get a

Re: Best way to convert sequence of bytes to long integer

2010-01-20 Thread Stefan Behnel
Steven D'Aprano, 20.01.2010 08:36: > I have a byte string (Python 2.x string), e.g.: > > s = "g%$f yg\n1\05" > assert len(s) == 10 > > I wish to convert it to a long integer, treating it as base-256. > Currently I'm using: > > def makelong(s): > n = 0 > for c in s: > n *= 256 >