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

2010-01-22 Thread Peter Otten
Steven D'Aprano wrote: > On Thu, 21 Jan 2010 17:56:00 -0800, [email protected] 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

Re: Symbols as parameters?

2010-01-22 Thread Alf P. Steinbach
* 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". I find it amazing that you continue this kind of ad hominem attack. You leave it open who you regard as trolling, but w

Re: Symbols as parameters?

2010-01-22 Thread Martin Drautzburg
Steven D'Aprano wrote: > I think this really is the correct solution for your problem. In > Python, the standard place to have such public constants is at the > module level, not the function or class. I think you're worrying > unnecessarily about "namespace pollution" -- the module namespace is >

Re: Symbols as parameters?

2010-01-22 Thread Martin Drautzburg
Carl Banks wrote: > I see. Well, Python is a poor choice for defining an internal DSL > (i.e., DSL using the general language's syntax), because it's > (deliberately) rigid in both grammar and semantics. I had this impression too. > Paul McGuire should be by to recommend PyParsing shortly.

Re: Symbols as parameters?

2010-01-22 Thread Alf P. Steinbach
* 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

Re: Python sys.prefix

2010-01-22 Thread Balazs Zachar
It looks like the python install environment is easily movable between two machine with the same OS (I mean, with the correct libraries)... Can I use this in production? Please consider the following test, after I use ./configure --prefix=/opt/python2.6.4 && make && make install: [r...@centos

Re: substitution

2010-01-22 Thread Duncan Booth
Wilbert Berendsen wrote: > # sort the keys, longest first, so 'aa' gets matched before 'a', because > # in Python regexps the first match (going from left to right) in a > # |-separated group is taken > keys = sorted(mapping.keys(), key=len, reverse=True) > This would do just as well (although

looking for Python live code reloading IDEs

2010-01-22 Thread George Oliver
hi, I'm wondering if there are any Python programming environments that enable live code reloading, for example something like the Scheme- based impromptu (but also meant for any kind of Python program, not just audio/visual generation). Currently I do this directly in my editor (for game developm

Re: Symbols as parameters?

2010-01-22 Thread Carl Banks
On Jan 21, 11:43 pm, Martin Drautzburg wrote: > > Paul McGuire should be by to recommend PyParsing shortly. > > I looked it up and it seems to be about parsing strings. This is not > what I am looking for as it would create a separate world outside of > python. But I haven't looked deeply yet. We

Re: Symbols as parameters?

2010-01-22 Thread Roald de Vries
Hi Martin, On Jan 21, 2010, at 8:43 AM, Martin Drautzburg wrote: 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",

Re: Symbols as parameters?

2010-01-22 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: (3) Then somone suggested to tie the constants to the function itself, as in def move(direction): print "moving %s" % direction move.UP = 'up' move.DOWN = 'down' This is quite nice. I would call it a horrible, horrible, horrible code smell. A stench in fact.

Re: Symbols as parameters?

2010-01-22 Thread Jan Kaliszewski
21-01-2010, 22:51:34 Martin Drautzburg wrote: Thanks for all the answers. Let me summarize (1) [...] (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. [...] (3) Then somone suggested to tie the constants to the funct

Re: Symbols as parameters?

2010-01-22 Thread Jan Kaliszewski
s/sollution/solution s/event implemented/even implemented Sorry *j -- http://mail.python.org/mailman/listinfo/python-list

Re: Symbols as parameters?

2010-01-22 Thread Ben Finney
Jean-Michel Pichavant writes: > Steven D'Aprano wrote: > > I would call it a horrible, horrible, horrible code smell. A stench > > in fact. […] > As soon as it is properly documented, as a public interface should be, > it becomes an acceptable design, IMO. […] So your position seems to be that

decimal threading cost?

2010-01-22 Thread Robin Becker
Does using the decimal module incur a penalty because it imports threading or do I have to actually start a thread? -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list

Re: decimal threading cost?

2010-01-22 Thread Mark Dickinson
On Jan 22, 11:11 am, Robin Becker wrote: > Does using the decimal module incur a penalty because it imports threading or > do > I have to actually start a thread? There is at least one threading-related performance penalty that doesn't involve the user actually starting a thread: any arithmetic

Re: Symbols as parameters?

2010-01-22 Thread Dave Angel
Roald de Vries wrote: Hi Martin, On Jan 21, 2010, at 8:43 AM, Martin Drautzburg wrote: 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", "dow

Re: Symbols as parameters?

2010-01-22 Thread Martin Drautzburg
On 22 Jan., 11:56, Roald de Vries wrote: > Hi Martin, > > On Jan 21, 2010, at 8:43 AM, Martin Drautzburg wrote: > > > > > > > Hello all, > > > When passing parameters to a function, you sometimes need a paramter > > which can only assume certain values, e.g. > > >        def move (direction): > >

[2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Gilles Ganault
Hello I use a dictionary to keep a list of users connected to a web site. To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll start with the next letter, eg. display the list from A...Zd

Re: Symbols as parameters?

2010-01-22 Thread Roald de Vries
On Jan 22, 2010, at 1:06 PM, Martin Drautzburg wrote: On 22 Jan., 11:56, Roald de Vries wrote: Hi Martin, On Jan 21, 2010, at 8:43 AM, Martin Drautzburg wrote: Hello all, When passing parameters to a function, you sometimes need a paramter which can only assume certain values, e.g.

Re: Symbols as parameters?

2010-01-22 Thread Mark Dickinson
On Jan 21, 10:57 pm, Martin Drautzburg wrote: > 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): > [...] Have you considered making 'scope' a cont

Re: decimal threading cost?

2010-01-22 Thread Robin Becker
On 22/01/2010 11:50, Mark Dickinson wrote: On Jan 22, 11:11 am, Robin Becker wrote: Does using the decimal module incur a penalty because it imports threading or do I have to actually start a thread? There is at least one threading-related performance penalty that doesn't involve the user act

Re: Symbols as parameters?

2010-01-22 Thread Steven D'Aprano
On Fri, 22 Jan 2010 09:12:46 +0100, Martin Drautzburg wrote: > Defining those symbols at the module level is absolutely fine with me. > The namespace pollution is indeed my biggest worry. You see, I want to > be able to type in lots of lines with little effort. Preferably I would > want to type >

Re: Symbols as parameters?

2010-01-22 Thread Jean-Michel Pichavant
Ben Finney wrote: Jean-Michel Pichavant writes: Steven D'Aprano wrote: I would call it a horrible, horrible, horrible code smell. A stench in fact. […] As soon as it is properly documented, as a public interface should be, it becomes an acceptable design, IMO. […]

Re: Symbols as parameters?

2010-01-22 Thread Steven D'Aprano
On Fri, 22 Jan 2010 09:29:18 +0100, Alf P. Steinbach wrote: > But have you tested this within a function or class, which is what the > use of "locals" implies? > > The reason that I ask is that in the documentation of locals() it says > this: > >Note >The contents of this dictionary shou

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Jean-Michel Pichavant
Gilles Ganault wrote: Hello I use a dictionary to keep a list of users connected to a web site. To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll start with the next letter, eg. disp

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Jean-Michel Pichavant
Jean-Michel Pichavant wrote: Gilles Ganault wrote: Hello I use a dictionary to keep a list of users connected to a web site. To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll start

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Gilles Ganault
On Fri, 22 Jan 2010 13:17:44 +0100, Gilles Ganault wrote: >I see that dictionaries can be sorted using the... sort() method, but >is it possible to have Python start sorting from a different letter? Looks like the solution is to read the list of keys into a list, sort the list, and then use this

Re: Symbols as parameters?

2010-01-22 Thread Alf P. Steinbach
* Steven D'Aprano -> Alf P. Steinbach: No, you got it spot on. Not to discourage you, but you're at least the third person who pointed this out in this thread. I get the impression that there's some message traffic that I don't see, perhaps on the mailing list, since (a) I haven't seen that

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Steven D'Aprano
On Fri, 22 Jan 2010 13:17:44 +0100, Gilles Ganault wrote: > Hello > > I use a dictionary to keep a list of users connected to a web site. > > To avoid users from creating login names that start with digits in order > to be listed at the top, I'd like to sort the list differently every > minute s

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Steven D'Aprano
On Fri, 22 Jan 2010 13:24:05 +, Steven D'Aprano wrote: > On Fri, 22 Jan 2010 13:17:44 +0100, Gilles Ganault wrote: [...] >> I see that dictionaries can be sorted using the... sort() method, but >> is it possible to have Python start sorting from a different letter? > > You can write a custome

Re: Symbols as parameters?

2010-01-22 Thread Wolfgang Rohdewald
On Friday 22 January 2010, Alf P. Steinbach wrote: > I get the impression that there's some message traffic that I don't > see > For example, the recent thread "Covert number into string" started > with a reply in my newreader, using EternalSeptember's NNTP host. > > It also starts with a reply

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Neil Cerutti
On 2010-01-22, Gilles Ganault wrote: > Hello > > I use a dictionary to keep a list of users connected to a web > site. > > To avoid users from creating login names that start with digits > in order to be listed at the top, I'd like to sort the list > differently every minute so that it'll start wi

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Gilles Ganault
On 22 Jan 2010 13:35:26 GMT, Neil Cerutti wrote: >Resorting is more work than is needed. Just choose a different >starting index each time you display the names, and set up your >lister to wrap-around to your arbitrary starting index. Thanks. In this case, it means that in each loop iteration, I

Consume an iterable

2010-01-22 Thread Muhammad Alkarouri
In the python help for itertools, the following function is provided: def consume(iterator, n): "Advance the iterator n-steps ahead. If n is none, consume entirely." collections.deque(islice(iterator, n), maxlen=0) What is the advantage of using a collections.deque against, say, the follo

Re: Symbols as parameters?

2010-01-22 Thread Alf P. Steinbach
* Steven D'Aprano: One implementation-specific trick is that modifying locals does actually work inside a class definition (at least in Python 2.5): class Foo(object): ... x = 1 ... print locals() ... locals()['x'] = 2 ... {'x': 1, '__module__': '__main__'} Foo.x 2 But it doe

Re: Change sorting order?

2010-01-22 Thread Jon Clements
On Jan 22, 1:58 pm, Gilles Ganault wrote: > On 22 Jan 2010 13:35:26 GMT, Neil Cerutti wrote: > > >Resorting is more work than is needed. Just choose a different > >starting index each time you display the names, and set up your > >lister to wrap-around to your arbitrary starting index. > > Thanks

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Gilles Ganault
On Fri, 22 Jan 2010 14:09:43 +0100, Jean-Michel Pichavant wrote: >Sorry, the code I provided produce this output: > >['1a', 'a', 'ac', 'av', 'b', 'c'] >['a', 'ac', 'av', 'b', 'c', '1a'] >['b', 'c', '1a', 'a', 'ac', 'av'] >['c', '1a', 'a', 'ac', 'av', 'b'] >['1a', 'a', 'ac', 'av', 'b', 'c'] > >whic

Re: Symbols as parameters?

2010-01-22 Thread Alf P. Steinbach
* Wolfgang Rohdewald: On Friday 22 January 2010, Alf P. Steinbach wrote: I get the impression that there's some message traffic that I don't see For example, the recent thread "Covert number into string" started with a reply in my newreader, using EternalSeptember's NNTP host. It also start

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Jan Kaliszewski
22-01-2010 Steven D'Aprano wrote: On Fri, 22 Jan 2010 13:17:44 +0100, Gilles Ganault wrote: To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll start with the next letter, eg. displ

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Dave Angel
Gilles Ganault wrote: Hello I use a dictionary to keep a list of users connected to a web site. To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll start with the next letter, eg. disp

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Gilles Ganault
On Fri, 22 Jan 2010 09:49:32 -0500, Dave Angel wrote: >Seems to me the other solutions I've seen so far are more complex than >needed. I figure you either want an unordered list, in which case you >could use random.shuffle(), or you want a list that's sorted, but starts >somewhere in the middl

Re: Consume an iterable

2010-01-22 Thread Arnaud Delobelle
Muhammad Alkarouri writes: > In the python help for itertools, the following function is provided: > > def consume(iterator, n): > "Advance the iterator n-steps ahead. If n is none, consume > entirely." > collections.deque(islice(iterator, n), maxlen=0) > > What is the advantage of using

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Arnaud Delobelle
Gilles Ganault writes: > On Fri, 22 Jan 2010 09:49:32 -0500, Dave Angel wrote: >>Seems to me the other solutions I've seen so far are more complex than >>needed. I figure you either want an unordered list, in which case you >>could use random.shuffle(), or you want a list that's sorted, but s

Re: Consume an iterable

2010-01-22 Thread Arnaud Delobelle
Muhammad Alkarouri writes: > In the python help for itertools, the following function is provided: > > def consume(iterator, n): > "Advance the iterator n-steps ahead. If n is none, consume > entirely." > collections.deque(islice(iterator, n), maxlen=0) > > What is the advantage of using

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Duncan Booth
Jean-Michel Pichavant wrote: > Here is one possible solution > > l = ['1a', 'a', 'b','c','av','ac'] # you mentioned a dictionary in your > post, if so, l = myDict.keys() > l.sort() # sort your list once and for all > for start in '1abcd': > result = [name for name in l if name[0] >= start]

Re: Consume an iterable

2010-01-22 Thread Jan Kaliszewski
In the python help for itertools, the following function is provided: def consume(iterator, n): "Advance the iterator n-steps ahead. If n is none, consume entirely." collections.deque(islice(iterator, n), maxlen=0) What is the advantage of using a collections.deque against, say, the foll

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Jan Kaliszewski
PS. 22-01-2010 o 15:44:28 Jan Kaliszewski wrote: 22-01-2010, 14:58:58 Gilles Ganault wrote: On 22 Jan 2010 13:35:26 GMT, Neil Cerutti wrote: Resorting is more work than is needed. Just choose a different starting index each time you display the names, and set up your lister to wrap-around

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Steven D'Aprano
On Fri, 22 Jan 2010 13:35:26 +, Neil Cerutti wrote: > On 2010-01-22, Gilles Ganault wrote: >> Hello >> >> I use a dictionary to keep a list of users connected to a web site. >> >> To avoid users from creating login names that start with digits in >> order to be listed at the top, I'd like to

Re: Writing a string.ishex function

2010-01-22 Thread Albert van der Horst
In article , MRAB wrote: >D'Arcy J.M. Cain wrote: >> On Thu, 14 Jan 2010 07:52:58 -0800 (PST) >> chandra wrote: >>> Folks, >>> >>> I am new to Python and could not find a function along the lines of >> >> Welcome. >> >>> string.ishex in Python. There is however, a string.hexdigits constant >>> i

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Neil Cerutti
On 2010-01-22, Steven D'Aprano wrote: > On Fri, 22 Jan 2010 13:35:26 +, Neil Cerutti wrote: >> On 2010-01-22, Gilles Ganault wrote: >>> Hello >>> >>> I use a dictionary to keep a list of users connected to a web site. >>> >>> To avoid users from creating login names that start with digits in

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Jean-Michel Pichavant
Gilles Ganault wrote: On Fri, 22 Jan 2010 14:09:43 +0100, Jean-Michel Pichavant wrote: Sorry, the code I provided produce this output: ['1a', 'a', 'ac', 'av', 'b', 'c'] ['a', 'ac', 'av', 'b', 'c', '1a'] ['b', 'c', '1a', 'a', 'ac', 'av'] ['c', '1a', 'a', 'ac', 'av', 'b'] ['1a', 'a', 'ac', 'a

Re: maintain 2 versions of python on my computer

2010-01-22 Thread Aahz
In article , Duncan Booth wrote: > >That seems overkill. This does pretty much the same thing: > > @(C:\Python26\Python -x %~f0 %* || pause) && goto:EOF > import sys > print sys.version > # raise RuntimeError # uncomment to trigger the 'pause' What version of Windows is

Re: maintain 2 versions of python on my computer

2010-01-22 Thread Alf P. Steinbach
* Aahz: In article , Duncan Booth wrote: That seems overkill. This does pretty much the same thing: @(C:\Python26\Python -x %~f0 %* || pause) && goto:EOF import sys print sys.version # raise RuntimeError # uncomment to trigger the 'pause' What version of Wi

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Steven D'Aprano
On Fri, 22 Jan 2010 09:49:32 -0500, Dave Angel wrote: > Seems to me the other solutions I've seen so far are more complex than > needed. I figure you either want an unordered list, in which case you > could use random.shuffle(), or you want a list that's sorted, but starts > somewhere in the midd

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Jean-Michel Pichavant
Jean-Michel Pichavant wrote: Gilles Ganault wrote: On Fri, 22 Jan 2010 14:09:43 +0100, Jean-Michel Pichavant wrote: Sorry, the code I provided produce this output: ['1a', 'a', 'ac', 'av', 'b', 'c'] ['a', 'ac', 'av', 'b', 'c', '1a'] ['b', 'c', '1a', 'a', 'ac', 'av'] ['c', '1a', 'a', 'ac', 'a

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Steven D'Aprano
On Fri, 22 Jan 2010 15:57:07 +, Neil Cerutti wrote: > On 2010-01-22, Steven D'Aprano > wrote: >> Unless you can predict what index to use for (say) names starting with >> "B", then your scheme doesn't work. In order to find that index, you >> have to do a linear search of the list after every

Re: subprocess troubles

2010-01-22 Thread Nobody
On Thu, 21 Jan 2010 11:25:08 +0100, Tomas Pelka wrote: > have a problem with following piece of code: > > -- > import subprocess > > paattern = "python" > cmd = "/usr/bin/locate" > arg1 = " -i" > arg2 = " -d /var/www/books/mlocate.db" > arg3 = str(

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Neil Cerutti
On 2010-01-22, Steven D'Aprano wrote: >> O(N*Log N) + O(N) == O(N**2)? > > Oops! :( > > Of course, the sort is in fast C, and the linear search is in > relatively slow Python, so it is quite conceivable that for > realistic amounts of data, the time could be dominated by the > searching. > > Or t

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Dave Angel
Gilles Ganault wrote: On Fri, 22 Jan 2010 09:49:32 -0500, Dave Angel wrote: Seems to me the other solutions I've seen so far are more complex than needed. I figure you either want an unordered list, in which case you could use random.shuffle(), or you want a list that's sorted, but starts

Re: maintain 2 versions of python on my computer

2010-01-22 Thread Duncan Booth
[email protected] (Aahz) wrote: > In article , > Duncan Booth wrote: >> >>That seems overkill. This does pretty much the same thing: >> >> @(C:\Python26\Python -x %~f0 %* || pause) && goto:EOF >> import sys >> print sys.version >> # raise RuntimeError # uncomme

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Gilles Ganault
On 22 Jan 2010 15:24:58 GMT, Duncan Booth wrote: >Here's another: Thanks for the sample. It work great, except that it also runs when the header character doesn't match any item in the list: === import bisect connected = [] connected.append("_test") connected.append("-test") connected.appen

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Gilles Ganault
On Fri, 22 Jan 2010 17:21:02 +0100, Jean-Michel Pichavant wrote: >Ok I realized that picking up a random index prevent from grouping names >starting with the same letter (to ease visual lookup). >Then go for the random char, and use char comparison (my first example). Yup, I think it's a good en

Re: * operator in python tutorial

2010-01-22 Thread ben
On Jan 20, 8:30 pm, Gringo wrote: > 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.

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Dave Angel
Steven D'Aprano wrote: On Fri, 22 Jan 2010 09:49:32 -0500, Dave Angel wrote: Seems to me the other solutions I've seen so far are more complex than needed. I figure you either want an unordered list, in which case you could use random.shuffle(), or you want a list that's sorted, but starts

Re: counting lines of code

2010-01-22 Thread Phlip
On Jan 21, 9:00 pm, Michele Simionato wrote: > Just for fun I have run cloc on our trunk: > > SUM:                8743    272238    215871   1470139 x   1.84 = > 2708354.95 Nice! My favorite version of a cloc system can distinguish test from production code. That's why I always use executable c

Re: Consume an iterable

2010-01-22 Thread Raymond Hettinger
On Jan 22, 6:13 am, Muhammad Alkarouri wrote: > In the python help for itertools, the following function is provided: > > def consume(iterator, n): >     "Advance the iterator n-steps ahead. If n is none, consume > entirely." >     collections.deque(islice(iterator, n), maxlen=0) > > What is the a

list.pop(0) vs. collections.dequeue

2010-01-22 Thread Steve Howell
The v2.6.4 version of the tutorial says this: ''' It is also possible to use a list as a queue, where the first element added is the first element retrieved (“first-in, first-out”); however, lists are not efficient for this purpose. While appends and pops from the end of list are fast, doing inser

Re: Symbols as parameters?

2010-01-22 Thread Martin Drautzburg
Mark Dickinson wrote: > On Jan 21, 10:57 pm, Martin Drautzburg > wrote: >> 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): >> [...] > > Have you

py2exe deal with python command line inside a program

2010-01-22 Thread susan_kijiji
Hi, I need to create a python subprogress, like this: myProcess = subprocess.Popen([sys.executable, 'C:\myscript.py'], env=env, stdin=subprocess.PIPE, stdout=subprocess.PIPE) sys.executable was printed out as ''C:\\Pyth

A.x vs. A["x"]

2010-01-22 Thread Martin Drautzburg
This has probably been asekd a million times, but if someone could give a short answer anyways I's be most grateful. What is it that allows one to write A.x? If I have a variable A, then what to I have to assign to it to A.x becomes valid? Or even further: what do I have to do so I can write A.x=

Re: A.x vs. A["x"]

2010-01-22 Thread Steve Howell
On Jan 22, 11:29 am, Martin Drautzburg wrote: > This has probably been asekd a million times, but if someone could give > a short answer anyways I's be most grateful. Not sure there is exactly a short answer, and I am only qualified to maybe clarify some of the things you can and cannot do, not e

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Chris Rebert
On Fri, Jan 22, 2010 at 11:14 AM, Steve Howell wrote: > The v2.6.4 version of the tutorial says this: > > ''' > It is also possible to use a list as a queue, where the first element > added is the first element retrieved (“first-in, first-out”); however, > lists are not efficient for this purpose.

Re: Symbols as parameters?

2010-01-22 Thread Martin Drautzburg
Martin Drautzburg wrote: >> with scope(): >> # ... >> # use up, down, left, right here >> >> # up, down, left, right no longer defined after the with block exits. Just looked it up again. It's a cool thing. Too bad my locals() hack would still be required. The result would be less noisy

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Steve Howell
On Jan 22, 12:14 pm, Chris Rebert wrote: > On Fri, Jan 22, 2010 at 11:14 AM, Steve Howell wrote: > > The v2.6.4 version of the tutorial says this: > > > ''' > > It is also possible to use a list as a queue, where the first element > > added is the first element retrieved (“first-in, first-out”);

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread John Posner
On 1/22/2010 7:17 AM, Gilles Ganault wrote: Hello I use a dictionary to keep a list of users connected to a web site. To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll start with the

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Christian Heimes
Steve Howell wrote: > Is that really true in CPython? It seems like you could advance the > pointer instead of shifting all the elements. It would create some > nuances with respect to reclaiming the memory, but it seems like an > easy way to make lists perform better under a pretty reasonable us

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Steve Howell
On Jan 22, 12:40 pm, Christian Heimes wrote: > Steve Howell wrote: > > Is that really true in CPython?  It seems like you could advance the > > pointer instead of shifting all the elements.  It would create some > > nuances with respect to reclaiming the memory, but it seems like an > > easy way t

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Arnaud Delobelle
Steve Howell writes: > On Jan 22, 12:14 pm, Chris Rebert wrote: >> On Fri, Jan 22, 2010 at 11:14 AM, Steve Howell wrote: >> > The v2.6.4 version of the tutorial says this: >> >> > ''' >> > It is also possible to use a list as a queue, where the first element >> > added is the first element retr

Re: looking for Python live code reloading IDEs

2010-01-22 Thread Mike Driscoll
On Jan 22, 3:16 am, George Oliver wrote: > hi, I'm wondering if there are any Python programming environments > that enable live code reloading, for example something like the Scheme- > based impromptu (but also meant for any kind of Python program, not > just audio/visual generation). > > Current

Re: simple pub/sub

2010-01-22 Thread Mike Driscoll
On Jan 21, 10:54 am, Steve Howell wrote: > Hi, I'm looking for ideas on building a simple architecture that > allows a bunch of independent Python processes to exchange data using > files and perform calculations. > > One Python program would be collecting data from boat instruments on a > serial

Re: * operator in python tutorial

2010-01-22 Thread Terry Reedy
On 1/22/2010 12:57 PM, ben wrote: On Jan 20, 8:30 pm, Gringo wrote: I am following through the python tutorial which gets to a line that uses the * operator with zip(). All such questions are at least briefly answered in my complete python3 symbol glossary (all syntax usages) at http://code

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Christian Heimes
Steve Howell wrote: > I disagree that Python code rarely pops elements off the top of a > list. There are perfectly valid use cases for wanting a list over a > dequeue without having to pay O(N) for pop(0). Maybe we are just > quibbling over the meaning of "rarely." I was speaking from my own po

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Steve Howell
On Jan 22, 1:08 pm, Arnaud Delobelle wrote: > Steve Howell writes: > > On Jan 22, 12:14 pm, Chris Rebert wrote: > >> On Fri, Jan 22, 2010 at 11:14 AM, Steve Howell wrote: > >> > The v2.6.4 version of the tutorial says this: > > >> > ''' > >> > It is also possible to use a list as a queue, where

Re: counting lines of code

2010-01-22 Thread Steve Holden
Robert Kern wrote: > On 2010-01-21 15:31 , Phlip wrote: >> Aahz wrote: >>> In article >>> <[email protected]>, >>> Phlip wrote: On Jan 20, 11:20=A0pm, Michele Simionato wrote: > pylint does too many things, I want something fast that ju

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Terry Reedy
On 1/22/2010 2:14 PM, Steve Howell wrote: The v2.6.4 version of the tutorial says this: Is that really true in CPython? It seems like you could advance the pointer instead of shifting all the elements. It would create some nuances with respect to reclaiming the memory, but it seems like an e

Re: simple pub/sub

2010-01-22 Thread bobicanprogram
On Jan 21, 11:54 am, Steve Howell wrote: > Hi, I'm looking for ideas on building a simple architecture that > allows a bunch of independent Python processes to exchange data using > files and perform calculations. > > One Python program would be collecting data from boat instruments on a > serial

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Christian Heimes
Arnaud Delobelle wrote: > I made the comment you quoted. In CPython, it is O(n) to delete/insert > an element at the start of the list - I know it because I looked at the > implementation a while ago. This is why collections.deque exists I > guess. I don't know how they are implemented but inser

Re: counting lines of code

2010-01-22 Thread Wilbert Berendsen
Op donderdag 21 januari 2010 schreef Michele: > I need a small utility to count the lines of Python code in a > directory, traversing subdirectories and ignoring comments and > docstrings. sloccount can do this. http://www.dwheeler.com/sloccount/ Met vriendelijke groet, Wilbert Berendsen -- h

Re: looking for Python live code reloading IDEs

2010-01-22 Thread Cameron Simpson
On 22Jan2010 13:19, Mike Driscoll wrote: | On Jan 22, 3:16 am, George Oliver wrote: | > hi, I'm wondering if there are any Python programming environments | > that enable live code reloading, for example something like the Scheme- | > based impromptu (but also meant for any kind of Python program

Re: A.x vs. A["x"]

2010-01-22 Thread Terry Reedy
On 1/22/2010 2:29 PM, Martin Drautzburg wrote: This has probably been asekd a million times, but if someone could give a short answer anyways I's be most grateful. What is it that allows one to write A.x? If I have a variable A, You do not really have a 'variable'. You have a name A bound to a

Using dictionary key as a regular expression class

2010-01-22 Thread Chris Jones
I was writing a script that counts occurrences of characters in source code files: #!/usr/bin/python import codecs tcounters = {} f = codecs.open('/home/gavron/git/screen/src/screen.c', 'r', "utf-8") for uline in f: lline = [] for char in uline[:-1]: lline += [char] counters = {} for

Re: Bare Excepts

2010-01-22 Thread Aahz
In article <80c56956-f28e-47a3-a723-3a5e3fd29...@j19g2000yqk.googlegroups.com>, [email protected] wrote: >On Jan 2, 9:35=A0pm, Dave Angel wrote: >> >> In Windows, there is a way to do it. It's just not exposed to the >> Python built-in function open(). You use the CreateFile() function, >> wit

Re: Create object name from string value?

2010-01-22 Thread Gnarlodious
On Jan 21, 9:21 am, Dave Angel wrote: > Put it inside a dummy class, as follows: This has been very educational, thank you for all the suggestions. Here is the resulting code: class Property: pass # example of a dummy class Plist = Property() # create a Plist object from the dummy class # accu

Re: Using dictionary key as a regular expression class

2010-01-22 Thread Arnaud Delobelle
Chris Jones writes: > I was writing a script that counts occurrences of characters in source > code files: > > #!/usr/bin/python > import codecs > tcounters = {} > f = codecs.open('/home/gavron/git/screen/src/screen.c', 'r', "utf-8") > for uline in f: > lline = [] > for char in uline[:-1]: >

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Steve Howell
On Jan 22, 1:29 pm, Christian Heimes wrote: > Steve Howell wrote: > > I disagree that Python code rarely pops elements off the top of a > > list.  There are perfectly valid use cases for wanting a list over a > > dequeue without having to pay O(N) for pop(0).  Maybe we are just > > quibbling over

Patch for IDLE/OS X to work with Tk-Cocoa

2010-01-22 Thread G73
im trying to update a patch. here is link to various patches http://bugs.python.org/issue6075 how do i update the patch, say for EditorWindow.patch. i have located my python installation the EditorWindow.py, and i can see some differences (which lines from the patch actually go into the EditorWind

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Dave Angel
Steve Howell wrote: On Jan 22, 12:40 pm, Christian Heimes wrote: Steve Howell wrote: Is that really true in CPython? It seems like you could advance the pointer instead of shifting all the elements. It would create some nuances with respect to reclaiming the memory, but it seems like

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Steve Howell
On Jan 22, 1:32 pm, Terry Reedy wrote: > On 1/22/2010 2:14 PM, Steve Howell wrote: > > > The v2.6.4 version of the tutorial says this: > > Is that really true in CPython?  It seems like you could advance the > > pointer instead of shifting all the elements.  It would create some > > nuances with r

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Dave Angel
Arnaud Delobelle wrote: Steve Howell writes: On Jan 22, 12:14 pm, Chris Rebert wrote: I made the comment you quoted. In CPython, it is O(n) to delete/insert an element at the start of the list - I know it because I looked at the implementation a while ago. This is why collections.

  1   2   >