Re: Symbols as parameters?

2010-01-21 Thread Carl Banks
On Jan 21, 1:51 pm, Martin Drautzburg wrote: > Thanks for all the answers. Let me summarize [snip] > (2) Using enum's was suggested. That is good to know, but again it is > just a way to define constants in the caller's namespace. It'll at least corral the symbols you want. [snip] > (4) Finally

Re: counting lines of code

2010-01-21 Thread Robert Kern
On 2010-01-21 15:31 , Phlip wrote: Aahz wrote: In article <7e09df6a-cda1-480e-a971-8f8a70ac4...@b9g2000yqd.googlegroups.com>, Phlip wrote: On Jan 20, 11:20=A0pm, Michele Simionato wrote: pylint does too many things, I want something fast that just counts the lines and can be run on thousands

Re: Symbols as parameters?

2010-01-21 Thread Ben Finney
Carl Banks writes: > On Jan 21, 1:51 pm, Martin Drautzburg > wrote: > > (2) Using enum's was suggested. That is good to know, but again it > > is just a way to define constants in the caller's namespace. > > It'll at least corral the symbols you want. It also satisfies the strongly-expressed de

Re: Python and Tkinter Programming by John Grayson

2010-01-21 Thread Ethan Furman
Peter wrote: On Jan 15, 9:12 am, Kevin Walzer wrote: On Jan 15, 6:24 am, Mark Roseman wrote: Peter wrote: Besides, the book is mainly about using Python with Tkinter - and Tkinter hasn't changed that much since 2000, so I believe it is just as relevant today as it was back then. I'd sa

deriving MySQLdb class

2010-01-21 Thread tekion
All, I am trying to write a class which inherits from MySQLdb class. Below is code snippet: import MySQLdb import sys class msql_connect(MySQLdb): def __init__(self): self.host = "hostname" self.user = "user" self.password = "passoword" self.database

Default return values for out-of-bounds list item

2010-01-21 Thread gburde...@gmail.com
Is there a built-in method in python that lets you specify a "default" value that will be returned whenever you try to access a list item that is out of bounds? Basically, it would be a function like this: def item(x,index,default): try: return x[index] except IndexError: return

Re: Symbols as parameters?

2010-01-21 Thread Steven D'Aprano
On Thu, 21 Jan 2010 22:51:34 +0100, Martin Drautzburg wrote: > Thanks for all the answers. Let me summarize > > (1) I fail to see the relevance of >  >>> def move( direction ): > ...   print( "move " + str( direction ) ) ... >  >>> move( "up" ) > move up I'm glad it's not just me then. > not o

Re: Create object name from string value?

2010-01-21 Thread Steven D'Aprano
On Thu, 21 Jan 2010 06:23:17 -0800, Gnarlodious wrote: >> The right way to solve this problem is with a dictionary: >> >> for name in ["object1", "object2", "object3"]: >>     d = {name: classname()} >>     print d[name] > > This works! However I end up saying: > > d['Server'].Config.BaseURL >

Re: Default return values for out-of-bounds list item

2010-01-21 Thread Steven D'Aprano
On Thu, 21 Jan 2010 17:56:00 -0800, gburde...@gmail.com wrote: > Is there a built-in method in python that lets you specify a "default" > value that will be returned whenever you try to access a list item that > is out of bounds? No. > Basically, it would be a function like this: > > def item

Re: Default return values for out-of-bounds list item

2010-01-21 Thread MRAB
gburde...@gmail.com wrote: Is there a built-in method in python that lets you specify a "default" value that will be returned whenever you try to access a list item that is out of bounds? Basically, it would be a function like this: def item(x,index,default): try: return x[index] exc

Re: Symbols as parameters?

2010-01-21 Thread MRAB
Steven D'Aprano wrote: [snip] An example from the standard library: the re module defines constants I, L, M, etc. representing flags that are passed to the re.compile. They are implemented as integers so they can easily be combined with &, but another implementation might use symbols. You will

Re: py2exe and pydocs. Downloads?

2010-01-21 Thread Jorgen Grahn
On Thu, 2010-01-21, Gib Bogle wrote: > Gabriel Genellina wrote: > >> You found a bug. Looks like it depends on the environment, or what >> packages are installed, or something like that, because it worked on my >> other PC but not here. >> Please report it at http://bugs.python.org so it doesn't

Re: Symbols as parameters?

2010-01-21 Thread Steven D'Aprano
On Fri, 22 Jan 2010 02:42:55 +, MRAB wrote: > Steven D'Aprano wrote: > [snip] >> An example from the standard library: the re module defines constants >> I, L, M, etc. representing flags that are passed to the re.compile. >> They are implemented as integers so they can easily be combined with

Re: Default return values for out-of-bounds list item

2010-01-21 Thread Tim Chase
MRAB wrote: gburde...@gmail.com wrote: Is there a built-in method in python that lets you specify a "default" value that will be returned whenever you try to access a list item that is out of bounds? Basically, it would be a function like this: def item(x,index,default): try: return x[

Re: deriving MySQLdb class

2010-01-21 Thread Sean DiZazzo
On Jan 21, 5:48 pm, tekion wrote: > All, > I am trying to write a class which inherits from MySQLdb class.  Below > is code snippet: > import MySQLdb > import sys > > class  msql_connect(MySQLdb): >     def __init__(self): >         self.host     =  "hostname" >         self.user     = "user" >  

Re: deriving MySQLdb class

2010-01-21 Thread Sean DiZazzo
On Jan 21, 8:00 pm, tekion wrote: > Sean, > Thanks.  This is useful.  For future reference, how do I know what > class is in MySQLdb module? You have to explore. ;) I found the MySQLdb module, and looked inside the __init__.py. Then looked for "connect" and followed the trail. -- http://mail.

Re: deriving MySQLdb class

2010-01-21 Thread tekion
Sean, I did a little investigation, there are other classes besides Connection. So, could I only set up a derived class from Connection and still be able to use the connection to query database and retrieve data? -- http://mail.python.org/mailman/listinfo/python-list

Re: deriving MySQLdb class

2010-01-21 Thread Sean DiZazzo
On Jan 21, 8:17 pm, tekion wrote: > Sean, > I did a little investigation, there are other classes besides > Connection. So, could I only set up a derived class from Connection > and still be able to use the connection to query database and retrieve > data? Im not sure I understand you completely.

Re: counting lines of code

2010-01-21 Thread Michele Simionato
On Jan 21, 9:24 pm, Phlip wrote: > On Jan 20, 11:20 pm, Michele Simionato > wrote: > > > pylint does too many things, I want something fast that just counts > > the lines and can be run on thousands of files at once. > > cloc seems fine, I have just tried on 2,000 files and it gives me a > > repo

Re: Rounding up to the next 100

2010-01-21 Thread casevh
On Jan 21, 1:58 pm, noydb wrote: > Sorry, although what I really need is the string-number rounded UP > every time.  So if the number is 3890.32, it needs to go to 3900; if > the number is 3811.345, it needs to go to 3900 also. > > So, Florian's answer works. Another option is using math.ceil and

Re: Inheriting methods but over-riding docstrings

2010-01-21 Thread Gabriel Genellina
En Thu, 21 Jan 2010 03:17:40 -0300, Michele Simionato escribió: 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 o

Re: Memory usage problem of twisted server

2010-01-21 Thread Dieter Maurer
Victor Lin writes on Wed, 20 Jan 2010 02:52:25 -0800 (PST): > 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-ser

Re: substitution

2010-01-21 Thread Anthra Norell
Iain King wrote: On Jan 21, 2:18 pm, Wilbert Berendsen wrote: Op maandag 18 januari 2010 schreef Adi: keys = [(len(key), key) for key in mapping.keys()] keys.sort(reverse=True) keys = [key for (_, key) in keys] pattern = "(%s)" % "|".join(keys) repl = lambda x : mapping[x.grou

Re: Symbols as parameters?

2010-01-21 Thread Martin Drautzburg
Here is a complete expample using a decorator, still a bit noisy def move(aDirection): print "moving " + aDirection #Here comes the decorator def scope(aDict): def save(locals): """Set symbols in locals and remember their original state""" setSymbols={} unsetSymbol

Re: Symbols as parameters?

2010-01-21 Thread Stefan Behnel
Alf P. Steinbach, 21.01.2010 20:24: > Do you understand how bad that makes you look? I think the right thing to say at this point is "don't feed the troll". Stefan -- http://mail.python.org/mailman/listinfo/python-list

<    1   2