Re: Using dictionary key as a regular expression class

2010-01-22 Thread Terry Reedy
On 1/22/2010 9:58 PM, Chris Jones wrote: On Fri, Jan 22, 2010 at 08:46:35PM EST, Terry Reedy wrote: Do you mean I should just read the file one character at a time? Whoops, my misdirection (you can .read(1), but this is s l o w. I meant to suggest processing it a char at a time. 1. If

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

2010-01-22 Thread Steve Howell
On Jan 22, 11:10 pm, a...@pythoncraft.com (Aahz) wrote: > > >I know Python's number one concern will never be speed, but if Python > >makes an O(1) operation into an unnecessarily O(N) operation for no > >good reasons other than "it's too complicated, " or it "adds another > >pointer to the structu

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

2010-01-22 Thread Alf P. Steinbach
* Steve Howell: On Jan 22, 7:09 pm, Roy Smith wrote: In article <3ac173bd-4124-434d-b726-0b9baaeec...@36g2000yqu.googlegroups.com>, Steve Howell wrote: In my case I'm not really concerned about giving the memory back right away, it's more about keeping my code simple. Once I'm done with an

Re: Problems with the date of modification of files on the flash drive in windows

2010-01-22 Thread Nobody
On Fri, 22 Jan 2010 21:23:37 -0800, Aleksey wrote: > I write crossplatform program and have next problem under windows > (under linux is all OK) : > > I'm trying to get the UTC modification date of files on the flash > drive under windows. In the flash card system is FAT. Timestamps stored on a

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

2010-01-22 Thread Aahz
In article <83082e19-9130-45a8-91f2-8601c1fda...@22g2000yqr.googlegroups.com>, Steve Howell wrote: > >I really want to use list *normally* with all its perfectly good >semantics and reasonable implementation, except for its blind spot >with respect to popping the first element off the list. The

Re: medians for degree measurements

2010-01-22 Thread Steve Howell
On Jan 22, 10:29 pm, Nobody wrote: > On Fri, 22 Jan 2010 16:09:03 -0800, Steve Howell wrote: > > I just saw the thread for medians, and it reminded me of a problem > > that I need to solve.  We are writing some Python software for > > sailing, and we need to detect when we've departed from the med

Re: medians for degree measurements

2010-01-22 Thread Nobody
On Fri, 22 Jan 2010 16:09:03 -0800, Steve Howell wrote: > I just saw the thread for medians, and it reminded me of a problem > that I need to solve. We are writing some Python software for > sailing, and we need to detect when we've departed from the median > heading on the leg. Calculating arit

Re: medians for degree measurements

2010-01-22 Thread Steve Howell
On Jan 22, 5:12 pm, MRAB wrote: > Steve Howell wrote: > > I just saw the thread for medians, and it reminded me of a problem > > that I need to solve.  We are writing some Python software for > > sailing, and we need to detect when we've departed from the median > > heading on the leg.  Calculatin

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

2010-01-22 Thread Steve Howell
On Jan 22, 7:09 pm, Roy Smith wrote: > In article > <3ac173bd-4124-434d-b726-0b9baaeec...@36g2000yqu.googlegroups.com>, >  Steve Howell wrote: > > > In my case I'm not really concerned about giving the memory back right > > away, it's more about keeping my code simple.  Once I'm done with an > >

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

2010-01-22 Thread Steve Howell
On Jan 22, 6:20 pm, Steven D'Aprano wrote: > On Fri, 22 Jan 2010 14:38:18 -0800, Steve Howell wrote: > > I know the Python programmer could simply iterate through the list > > rather than popping off unused elements, but that just means that you > > not only tie up the memory for the pointers just

Problems with the date of modification of files on the flash drive in windows

2010-01-22 Thread Aleksey
Hi All, I write crossplatform program and have next problem under windows (under linux is all OK) : I'm trying to get the UTC modification date of files on the flash drive under windows. In the flash card system is FAT. In the winter time (2010 01 21) Date of modification: >>> op.getmtime('

Re: Mastering Python 3 I/O - Special Preview - Feb 5, 2010 (Chicago)

2010-01-22 Thread Chris Colbert
oops :) On Fri, Jan 22, 2010 at 9:41 PM, Steve Holden wrote: > Dave: > > New York classes went well this week, and there appears to be some > demand for Chicago training. How can we satisfy this demand to our > common profit? > > regards > Steve > > David Beazley wrote: > >

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

2010-01-22 Thread Roy Smith
In article <3ac173bd-4124-434d-b726-0b9baaeec...@36g2000yqu.googlegroups.com>, Steve Howell wrote: > In my case I'm not really concerned about giving the memory back right > away, it's more about keeping my code simple. Once I'm done with an > element, I do just want to pop it off and keep all

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

2010-01-22 Thread Roy Smith
In article , 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 to make

Re: Using dictionary key as a regular expression class

2010-01-22 Thread Chris Jones
On Fri, Jan 22, 2010 at 08:46:35PM EST, Terry Reedy wrote: > On 1/22/2010 4:47 PM, Chris Jones wrote: >> 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/

Re: Mastering Python 3 I/O - Special Preview - Feb 5, 2010 (Chicago)

2010-01-22 Thread Steve Holden
Dave: New York classes went well this week, and there appears to be some demand for Chicago training. How can we satisfy this demand to our common profit? regards Steve David Beazley wrote: > Mastering Python 3 I/O >** PyCON'2010 Tutorial Preview in Chicago **

Re: [ANN] hgview 1.2.0

2010-01-22 Thread Steve Holden
Stefan Behnel wrote: > For those who are a bit less fluent in French: > [...] ... and, while having access to e-mail, have not yet come across translate.google.com? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org

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

2010-01-22 Thread Steven D'Aprano
On Fri, 22 Jan 2010 14:38:18 -0800, Steve Howell wrote: > I know the Python programmer could simply iterate through the list > rather than popping off unused elements, but that just means that you > not only tie up the memory for the pointers just as long, but you also > prevent the objects themse

Re: PyArg_ParseTupleAndKeywords

2010-01-22 Thread Carl Banks
On Jan 22, 3:23 pm, "Mr.M" wrote: > Hi, > > i can't understand what i'm doing wrong. I have a c/api that implements > a new class. > In (initproc) function i have somethink like this: > > [code] > > (some declarations omitted here) You probably shouldn't have, that could be where the error is

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

2010-01-22 Thread Kevin Walzer
On 1/22/10 5:47 PM, G73 wrote: 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 patc

Re: Using dictionary key as a regular expression class

2010-01-22 Thread Terry Reedy
On 1/22/2010 4:47 PM, Chris Jones wrote: 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: medians for degree measurements

2010-01-22 Thread MRAB
Steve Howell wrote: I just saw the thread for medians, and it reminded me of a problem that I need to solve. We are writing some Python software for sailing, and we need to detect when we've departed from the median heading on the leg. Calculating arithmetic medians is straightforward, but comp

Re: medians for degree measurements

2010-01-22 Thread Robert Kern
On 2010-01-22 18:09 PM, Steve Howell wrote: I just saw the thread for medians, and it reminded me of a problem that I need to solve. We are writing some Python software for sailing, and we need to detect when we've departed from the median heading on the leg. Calculating arithmetic medians is s

medians for degree measurements

2010-01-22 Thread Steve Howell
I just saw the thread for medians, and it reminded me of a problem that I need to solve. We are writing some Python software for sailing, and we need to detect when we've departed from the median heading on the leg. Calculating arithmetic medians is straightforward, but compass bearings add a twi

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

2010-01-22 Thread Daniel Stutzbach
On Fri, Jan 22, 2010 at 5:27 PM, Steve Howell wrote: > I actually do expect Python to solve performance problems for me that > are more easily solved in core than in Python itself. So I guess > that's where we differ. > You might be interested in the extension type I wrote (the "blist") that lo

Re: Efficient Running Median

2010-01-22 Thread Aahz
In article <497af344-31b5-4d1a-9b1a-c3d82feb3...@j5g2000yqm.googlegroups.com>, Raymond Hettinger wrote: > >The performance of an IndexableSkiplist is similar to a B+tree but the >implementation in pure python is much simpler. Nice! Can you summarize why IndexableSkipList is simpler? -- Aahz (a

Re: Using dictionary key as a regular expression class

2010-01-22 Thread Chris Jones
On Fri, Jan 22, 2010 at 05:07:13PM EST, Arnaud Delobelle wrote: [..] > import codecs > from collections import defaultdict > > tcounters = defaultdict(int) > f = codecs.open('/home/gavron/git/screen/src/screen.c', 'r', "utf-8") > > for c in f.read(): > tcounters[c] += 1 > > for c, n in tco

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

2010-01-22 Thread Steve Howell
On Jan 22, 3:17 pm, Christian Heimes wrote: > Steve Howell wrote: > > That maybe would be an argument for just striking the paragraph from > > the tutorial.  If it's rare that people pop the head off the list in > > code that is performance critical or prominent, why bother to even > > mention it

PyArg_ParseTupleAndKeywords

2010-01-22 Thread Mr.M
Hi, i can't understand what i'm doing wrong. I have a c/api that implements a new class. In (initproc) function i have somethink like this: [code] (some declarations omitted here) static char* keywordlist[] = {"service", "event_type",

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

2010-01-22 Thread Steve Howell
On Jan 22, 2:54 pm, Dave Angel wrote: > 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 > >>> nuan

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

2010-01-22 Thread Christian Heimes
Steve Howell wrote: > That maybe would be an argument for just striking the paragraph from > the tutorial. If it's rare that people pop the head off the list in > code that is performance critical or prominent, why bother to even > mention it in the tutorial? How else are you going to teach new P

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.

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
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

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 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

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: 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: Bare Excepts

2010-01-22 Thread Aahz
In article <80c56956-f28e-47a3-a723-3a5e3fd29...@j19g2000yqk.googlegroups.com>, sjdevn...@yahoo.com 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

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: 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

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: 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: 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: 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 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: 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 >>> <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 ju

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: 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: * 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: 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: 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: 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: 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 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: [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 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: 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 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: 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

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=

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

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

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: 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

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: [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: * 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 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: [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: maintain 2 versions of python on my computer

2010-01-22 Thread Duncan Booth
a...@pythoncraft.com (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 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: [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: 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 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: [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 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: 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: 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: [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: [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: 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 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: [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: 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 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 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 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: [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 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: 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 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: 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: 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

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: [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

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: 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

  1   2   >