Re: "Advanced" Python programming book?

2010-01-11 Thread Aldo Ceccarelli
On 11 Gen, 21:47, webtourist wrote: > On Jan 10, 8:35 am, flow wrote: > > > I've just finished reading a sort of beginner Python book, and I know > > quite a bit now but I'm looking for a book that can teach me advanced > > aspects of Python - code optimisation, threading, etc. > > > Any recommen

Re: Dynamic HTML controls

2010-01-11 Thread alex23
On Jan 12, 1:26 pm, Alan Harris-Reid wrote: > Does anyone know where I can find any decent dynamically-constructed > HTML control classes (dropdown list, table, input field, checkbox, etc.) > written in Python. There's pyWeb[1], which seems pretty close to what you're asking for: mytable = tab

Re: Fractional Hours from datetime?

2010-01-11 Thread Alf P. Steinbach
* Steve Holden: Alf P. Steinbach wrote: * W. eWatson: Ben Finney wrote: "W. eWatson" writes: See my post about the datetime controversy about 3-4 posts up from yours. This forum is distributed, and there's no “up” or “3-4 messages” that is common for all readers. Could you give the Messag

Re: Fractional Hours from datetime?

2010-01-11 Thread David Robinow
On Mon, Jan 11, 2010 at 10:26 PM, Ben Finney wrote: > "Alf P. Steinbach" writes: > >> And considering this, and the fact that Google's archive is now the >> main Usenet archive, message id's are not that useful, really. > > You've demonstrated only that Google is an unreliable Usenet archive. > >

Re: Fractional Hours from datetime?

2010-01-11 Thread Ben Finney
"Alf P. Steinbach" writes: > And considering this, and the fact that Google's archive is now the > main Usenet archive, message id's are not that useful, really. You've demonstrated only that Google is an unreliable Usenet archive. One doesn't even need to use Usenet, in this case, since comp.l

Dynamic HTML controls

2010-01-11 Thread Alan Harris-Reid
Hi, Does anyone know where I can find any decent dynamically-constructed HTML control classes (dropdown list, table, input field, checkbox, etc.) written in Python. For example, for a HTML table I would like something like... MyTable = html_table() # instantiate class MyTable.data =

Re: Fractional Hours from datetime?

2010-01-11 Thread Steve Holden
Alf P. Steinbach wrote: > * W. eWatson: >> Ben Finney wrote: >>> "W. eWatson" writes: >>> See my post about the datetime controversy about 3-4 posts up from yours. >>> >>> This forum is distributed, and there's no “up” or “3-4 messages” that is >>> common for all readers. >>> >>> Could y

Re: Fractional Hours from datetime?

2010-01-11 Thread Alf P. Steinbach
* W. eWatson: Ben Finney wrote: "W. eWatson" writes: See my post about the datetime controversy about 3-4 posts up from yours. This forum is distributed, and there's no “up” or “3-4 messages” that is common for all readers. Could you give the Message-ID for that message? Sort of like oute

Re: "Advanced" Python programming book?

2010-01-11 Thread webtourist
On Jan 10, 8:35 am, flow wrote: > I've just finished reading a sort of beginner Python book, and I know > quite a bit now but I'm looking for a book that can teach me advanced > aspects of Python - code optimisation, threading, etc. > > Any recommendations? > > Cheers. Can you tell us what book i

Re: Fractional Hours from datetime?

2010-01-11 Thread Ben Finney
"W. eWatson" writes: > Ben Finney wrote: > > Could you give the Message-ID for that message? > > > Sort of like outer space I guess. No real direction. How would I find > the message ID? It is a field in the header of every message. Show the full header, and look for the field named ‘Message-ID’

Re: Fractional Hours from datetime?

2010-01-11 Thread W. eWatson
Ben Finney wrote: "W. eWatson" writes: See my post about the datetime controversy about 3-4 posts up from yours. This forum is distributed, and there's no “up” or “3-4 messages” that is common for all readers. Could you give the Message-ID for that message? Sort of like outer space I guess

Python tk Listbox: -listvariable class (on win XP)

2010-01-11 Thread Looney, James B
I mentioned that I figured out how to use a variable with a Python TK Listbox in my post (http://www.mail-archive.com/python-list@python.org/msg271288.html). Now, I'm trying to make a class, ListVar, that allows me to operate on a Listbox's listvariable as if it were a list. The problem is, it

Re: Fractional Hours from datetime?

2010-01-11 Thread W. eWatson
Martin P. Hellwig wrote: Martin P. Hellwig wrote: W. eWatson wrote: Maybe there's a more elegant way to do this. I want to express the result of datetime.datetime.now() in fractional hours. Here's one way. dt=datetime.datetime.now() xtup = dt.timetuple() h = xtup[3]+xtup[4]/60.0+xtup[5]/3600

Re: Fractional Hours from datetime?

2010-01-11 Thread W. eWatson
Martin P. Hellwig wrote: Martin P. Hellwig wrote: W. eWatson wrote: Maybe there's a more elegant way to do this. I want to express the result of datetime.datetime.now() in fractional hours. Here's one way. dt=datetime.datetime.now() xtup = dt.timetuple() h = xtup[3]+xtup[4]/60.0+xtup[5]/3600

Re: What is built-in method sub

2010-01-11 Thread Phlip
trailingPattern = '(\S*)\ +?\n' line = re.sub(trailingPattern, '\\1\n', line) What happens with this? trailingPattern = '\s+$' line = re.sub(trailingPattern, '', line) I'm guessing that $ terminates \s+'s greediness without snarfing the underlying \n. Then I'm guessing that

Re: Python File Search

2010-01-11 Thread Chris Rebert
2010/1/11 Eknath Venkataramani : > correct.txt snippet: > 1 2 1 > 1 3 3 > 1 5 21 > 1 7 19 > > union_output_TEMP.txt snippet: > 1 2 1_NN > 1 3 3_VBZ > 1 3 5_VBZ > 1 3 2_VBZ > 1 5 21_VB > 1 7 19_NN > 1 9 14_VB > > I need to get the output in categorized.txt as: > NN={1 7 19, 1 2 1} > VBZ={1 3 3} > VB

Re: shell access

2010-01-11 Thread Giorgos Tzampanakis
On 2010-01-11, monkeys paw wrote: > >>> print 'hey' > 'hey' > >>> # I want to access the shell here, how do i do that? Look into the commands module. -- http://mail.python.org/mailman/listinfo/python-list

Re: problem with multiprocessing and defaultdict

2010-01-11 Thread Robert Kern
On 2010-01-11 17:50 PM, wiso wrote: The problem now is this: start reading file r1_200909.log start reading file r1_200910.log readen 488832 lines from file r1_200910.log readen 517247 lines from file r1_200909.log with huge file (the real case) the program freeze. Is there a solution to avoid

Re: What is built-in method sub

2010-01-11 Thread John Machin
On Jan 12, 7:30 am, Jeremy wrote: > On Jan 11, 1:15 pm, "Diez B. Roggisch" wrote: > > > > > Jeremy schrieb: > > > > On Jan 11, 12:54 pm, Carl Banks wrote: > > >> On Jan 11, 11:20 am, Jeremy wrote: > > > >>> I just profiled one of my Python scripts and discovered that >99% of > > >>> the time wa

Re: Linking Python to multiple qt forms

2010-01-11 Thread trzewiczek
On 01/11/2010 11:57 PM, Zabin wrote: Hey! I am new to PyQt programming and am trying to activate a secondary qt form from a primary form. I am unsure as to how this will work as i am using pyuic4 to convert .ui file to .py and then importing it by: from SimLCM_GUI import Ui_main I am unsure as

Re: problem with multiprocessing and defaultdict

2010-01-11 Thread wiso
Robert Kern wrote: > On 2010-01-11 17:15 PM, wiso wrote: >> I'm using a class to read some data from files: >> >> import multiprocessing >> from collections import defaultdict >> >> def SingleContainer(): >> return list() >> >> >> class Container(defaultdict): >> """ >> this class s

Python File Search

2010-01-11 Thread Eknath Venkataramani
correct.txt snippet: 1 2 1 1 3 3 1 5 21 1 7 19 union_output_TEMP.txt snippet: 1 2 1_NN 1 3 3_VBZ 1 3 5_VBZ 1 3 2_VBZ 1 5 21_VB 1 7 19_NN 1 9 14_VB I need to get the output in categorized.txt as: NN={1 7 19, 1 2 1} VBZ={1 3 3} VB={1 5 21} in python. Kindly help 1 2 1 1 3 3 1 5 21 1 7 19 1 10 13 1

Re: problem with multiprocessing and defaultdict

2010-01-11 Thread Robert Kern
On 2010-01-11 17:15 PM, wiso wrote: I'm using a class to read some data from files: import multiprocessing from collections import defaultdict def SingleContainer(): return list() class Container(defaultdict): """ this class store odd line in self["odd"] and even line in self["

Re: What is built-in method sub

2010-01-11 Thread Steven D'Aprano
On Mon, 11 Jan 2010 13:51:48 -0800, Chris Rebert wrote: > On Mon, Jan 11, 2010 at 12:34 PM, Steven D'Aprano > wrote: >> If you can avoid regexes in favour of ordinary string methods, do so. >> In general, something like: >> >> source.replace(target, new) >> >> will potentially be much faster tha

Re: lightweight encryption of text file

2010-01-11 Thread John Bokma
Paul Rubin writes: > John Bokma writes: >>> Why EVER make anything yourself when you can buy it? >> >> Do you make your own processors? Your own hard disk drives? >> Why not? > > Well, if you try to make your own processors or hard drives, worst > normal outcome is they don't work and you try so

Re: Python Goldmine has been updated: http://preciseinfo.org/Convert/index_Convert_Python.html

2010-01-11 Thread John Bokma
ta...@mongo.net (tanix) writes: > Sorry to tell you, but I studied Google architecture in sufficient > detail to say what I am saying. http://groups.google.com/groups?lnk=hpsg&q=group%3Acomp.lang.python%20pyparsing -- John Bokma Read my blog: http://johnbokma.com/ Hire me (Perl/Python): http:

problem with multiprocessing and defaultdict

2010-01-11 Thread wiso
I'm using a class to read some data from files: import multiprocessing from collections import defaultdict def SingleContainer(): return list() class Container(defaultdict): """ this class store odd line in self["odd"] and even line in self["even"]. It is stupid, but it's only a

Linking Python to multiple qt forms

2010-01-11 Thread Zabin
Hey! I am new to PyQt programming and am trying to activate a secondary qt form from a primary form. I am unsure as to how this will work as i am using pyuic4 to convert .ui file to .py and then importing it by: from SimLCM_GUI import Ui_main I am unsure as to how the self.uicommands will fu

Re: lightweight encryption of text file

2010-01-11 Thread Robert Kern
On 2010-01-11 14:09 PM, Anthra Norell wrote: Robert Kern wrote: On 2010-01-09 03:52 AM, Anthra Norell wrote: "Don't use a random generator for encryption purposes!" warns the manual, of which fact I was reminded in no uncertain terms on this forum a few years ago when I proposed the following

Re: Python Goldmine has been updated: http://preciseinfo.org/Convert/index_Convert_Python.html

2010-01-11 Thread tanix
In article , Terry Reedy wrote: >On 1/11/2010 2:50 PM, tanix wrote: >> In article, Terry > Reedy wrote: > >>> This site pops up spam windowns. One was blocked, one managed to bypass >>> the popup blocker. Tnis is not friendly behaviour. >> >> I am sorry. But this is a known issue. >> This is one

Re: os.system function

2010-01-11 Thread Zabin
On Jan 12, 11:31 am, Jeremy Sanders wrote: > Zabin wrote: > > Thanks for the pointersi had a look around and found the site: > > http://www.microsoft.com/resources/documentation/windows/xp/all/prodd... > us/xcopy.mspx?mfr=true > > > > > to disable the prompt- i needed to include /y as below: >

Re: shell access

2010-01-11 Thread Tim Chase
monkeys paw wrote: How do you access the command line from the python interpreter? on unix: type python >>> print 'hey' 'hey' >>> # I want to access the shell here, how do i do that? If you're interactive, I'd just use standard process/job control, and hit control+Z to suspend and "fg"

Re: os.system function

2010-01-11 Thread Chris Rebert
On Mon, Jan 11, 2010 at 2:00 PM, Zabin wrote: > and just wondering- whats the drawback of using os.system() command Forgetting to properly escape your input. Simple example: filename = "foo bar.txt" os.system("rm "+filename) # uh-oh, we deleted 'foo' and 'bar.txt' instead The `subprocess` modu

Re: C Module's '1.#INF' changes to 'inf' at Python

2010-01-11 Thread Robert Kern
On 2010-01-11 14:31 PM, CELEN Erman wrote: (I also noticed that this behavior is same under standard NumPy 1.4 with standard Python 2.6 on Windows. If you call numpy.log10(0.0) you will get an "-inf" and no exceptions will be raised. Which is not the case with Python's standard math.log10(0.0) wh

Re: PIL how to display multiple images side by side

2010-01-11 Thread Alf P. Steinbach
* suresh.amritapuri: On Jan 9, 9:51 pm, "Alf P. Steinbach" wrote: * Lie Ryan: On 1/9/2010 8:43 AM, suresh.amritapuri wrote: Hi, In PIL, how to display multiple images in say m rows and n colums when I have m*n images. suresh Tkinter has PhotoImage widget and PIL has support for this widget:

Re: os.system function

2010-01-11 Thread Zabin
On Jan 12, 10:23 am, Chris Rebert wrote: > On Mon, Jan 11, 2010 at 12:43 PM, Zabin wrote: > > Hey everyone! > > > I am a new python programmer. I am trying to get the general file > > functionality with options of save and save as working. These save > > functions save a folder with multiple file

Re: how to duplicate array entries

2010-01-11 Thread Steven D'Aprano
On Mon, 11 Jan 2010 10:03:04 +0100, Alf P. Steinbach wrote: >>> A Python "list" is an array functionality-wise. >>> >>> If one isn't observant of that fact then one ends up with O(n^2) time >>> for the simplest things. >> >> Well that's certainly not true. Some operations may be O(N**2), but >> o

Re: What is built-in method sub

2010-01-11 Thread Chris Rebert
On Mon, Jan 11, 2010 at 12:34 PM, Steven D'Aprano wrote: > If you can avoid regexes in favour of ordinary string methods, do so. In > general, something like: > > source.replace(target, new) > > will potentially be much faster than: > > regex = re.compile(target) > regex.sub(new, source) > # equi

Re: xml.sax parsing elements with the same name

2010-01-11 Thread amadain
On Jan 11, 9:03 pm, John Bokma wrote: > amadain writes: > > On Jan 11, 7:26 pm, John Bokma wrote: > >> amadain writes: > >> > >> > uniqueId="1261124569.35725_PFS_1_1340035961"> > >> >     > >> >       > >> >           > >> >               > >> >                     > >> >               > >

Re: os.system function

2010-01-11 Thread Chris Rebert
On Mon, Jan 11, 2010 at 12:43 PM, Zabin wrote: > Hey everyone! > > I am a new python programmer. I am trying to get the general file > functionality with options of save and save as working. These save > functions save a folder with multiple files. Upon using the os.system > copy function- if my d

Re: Accessing python from a network share in windows 7

2010-01-11 Thread aj
On Jan 9, 3:55 am, Anssi Saari wrote: > aj writes: > > I access python from a network share. This works fine on XP but on > > windows 7 it throws the following error: > > > Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit > > (Intel)] on > > win32 > > Type "help", "copyright",

Re: shell access

2010-01-11 Thread Arnaud Delobelle
monkeys paw writes: > How do you access the command line from the > python interpreter? > > on unix: > > type python > print 'hey' > 'hey' # I want to access the shell here, how do i do that? Like this? >>> import os >>> os.system('echo $HOME') /Users/arno 0 >>> -- Arnaud -- htt

Re: What is built-in method sub

2010-01-11 Thread Arnaud Delobelle
Philip Semanchuk writes: > > I second the suggestion to use rstrip(), but for future reference you > should also check out the compile() function in the re module. You > might want to time the code above against a version using a compiled > regex to see how much difference it makes. The re module

Re: os.system function

2010-01-11 Thread Olof Bjarnason
2010/1/11 Zabin : > Hey everyone! > > I am a new python programmer. I am trying to get the general file > functionality with options of save and save as working. These save > functions save a folder with multiple files. Upon using the os.system > copy function- if my destination directory has files

RE: C Module's '1.#INF' changes to 'inf' at Python

2010-01-11 Thread CELEN Erman
>> (I also noticed that this behavior is same under standard NumPy 1.4 >> with standard Python 2.6 on Windows. If you call numpy.log10(0.0) you >> will get an "-inf" and no exceptions will be raised. Which is not the >> case with Python's standard math.log10(0.0) which will raise a >> ValueErro

Re: Python Goldmine has been updated: http://preciseinfo.org/Convert/index_Convert_Python.html

2010-01-11 Thread Terry Reedy
On 1/11/2010 2:50 PM, tanix wrote: In article, Terry Reedy wrote: This site pops up spam windowns. One was blocked, one managed to bypass the popup blocker. Tnis is not friendly behaviour. I am sorry. But this is a known issue. This is one of counter vendors doing these popups. They were c

Re: xml.sax parsing elements with the same name

2010-01-11 Thread John Bokma
amadain writes: > On Jan 11, 7:26 pm, John Bokma wrote: >> amadain writes: >> > > > uniqueId="1261124569.35725_PFS_1_1340035961"> >> >     >> >       >> >           >> >               >> >                     >> >               >> >           >> >           >> >               >> >    

Re: What is built-in method sub

2010-01-11 Thread Diez B. Roggisch
Philip Semanchuk schrieb: On Jan 11, 2010, at 3:30 PM, Jeremy wrote: On Jan 11, 1:15 pm, "Diez B. Roggisch" wrote: Jeremy schrieb: On Jan 11, 12:54 pm, Carl Banks wrote: On Jan 11, 11:20 am, Jeremy wrote: I just profiled one of my Python scripts and discovered that >99% of the time w

shell access

2010-01-11 Thread monkeys paw
How do you access the command line from the python interpreter? on unix: type python >>> print 'hey' 'hey' >>> # I want to access the shell here, how do i do that? -- http://mail.python.org/mailman/listinfo/python-list

Re: What is built-in method sub

2010-01-11 Thread Grant Edwards
On 2010-01-11, Steven D'Aprano wrote: [regarding profiling results] > I think you'll find that Python's regex engine is pretty much > optimised as well as it can be, short of a major re-write. But > to quote Jamie Zawinski: > > Some people, when confronted with a problem, think "I know, >

Re: What is built-in method sub

2010-01-11 Thread Philip Semanchuk
On Jan 11, 2010, at 3:30 PM, Jeremy wrote: On Jan 11, 1:15 pm, "Diez B. Roggisch" wrote: Jeremy schrieb: On Jan 11, 12:54 pm, Carl Banks wrote: On Jan 11, 11:20 am, Jeremy wrote: I just profiled one of my Python scripts and discovered that >99% of the time was spent in {built-in met

Re: Fundamental Function Question (beginner)

2010-01-11 Thread Scott
> There's nothing wrong with building dicts or other lookup tables outside > a function in order to avoid re-creating them every time the function is > called. Brilliant! I didn't think of that. I guess I accidentally did it right this time as I query that dictionary quite a few times from the fun

Re: Fundamental Function Question (beginner)

2010-01-11 Thread Steven D'Aprano
On Mon, 11 Jan 2010 18:57:09 +, MRAB wrote: > There's nothing wrong with building dicts or other lookup tables outside > a function in order to avoid re-creating them every time the function is > called. Actually there is, but the benefit (avoiding the re-creation of the table) may be worth

Re: Fundamental Function Question (beginner)

2010-01-11 Thread Scott
On Jan 11, 1:50 pm, Phlip wrote: > MRAB wrote: > > Scott wrote: > >> for prtnmS in open(portfpth): > >>     prtnmS = prtnmS.rstrip() > > There's nothing wrong with building dicts or other lookup tables outside > > a function in order to avoid re-creating them every time the function is > > called.

Re: What is built-in method sub

2010-01-11 Thread Terry Reedy
On 1/11/2010 3:02 PM, Jeremy wrote: I am using the re.sub command to remove trailing whitespace from lines in a text file. >>> help(str.rstrip) Help on method_descriptor: rstrip(...) S.rstrip([chars]) -> str Return a copy of the string S with trailing whitespace removed. If chars

Re: What is built-in method sub

2010-01-11 Thread J
On Mon, Jan 11, 2010 at 15:02, Jeremy wrote: > I am using the re.sub command to remove trailing whitespace from lines > in a text file.  The commands I use are copied below.  If you have any > suggestions on how they could be improved, I would love to know. Just curious, but if each line is simpl

os.system function

2010-01-11 Thread Zabin
Hey everyone! I am a new python programmer. I am trying to get the general file functionality with options of save and save as working. These save functions save a folder with multiple files. Upon using the os.system copy function- if my destination directory has files with similar names- i am ask

Re: What is built-in method sub

2010-01-11 Thread Steven D'Aprano
On Mon, 11 Jan 2010 11:20:34 -0800, Jeremy wrote: > I just profiled one of my Python scripts Well done! I'm not being sarcastic, or condescending, but you'd be AMAZED (or possibly not...) at how many people try to optimize their scripts *without* profiling, and end up trying to speed up parts

Re: lightweight encryption of text file

2010-01-11 Thread Paul Rubin
Anthra Norell writes: > Why EVER make anything yourself when you can buy it? http://en.wikipedia.org/wiki/Dunning-Kruger_effect -- http://mail.python.org/mailman/listinfo/python-list

Re: What is built-in method sub

2010-01-11 Thread Jeremy
On Jan 11, 1:15 pm, "Diez B. Roggisch" wrote: > Jeremy schrieb: > > > > > > > On Jan 11, 12:54 pm, Carl Banks wrote: > >> On Jan 11, 11:20 am, Jeremy wrote: > > >>> I just profiled one of my Python scripts and discovered that >99% of > >>> the time was spent in > >>> {built-in method sub} > >>>

Re: What is built-in method sub

2010-01-11 Thread Stephen Hansen
On Mon, Jan 11, 2010 at 12:02 PM, Jeremy wrote: > Your guess is correct. I had forgotten that I was using that > function. > > I am using the re.sub command to remove trailing whitespace from lines > in a text file. The commands I use are copied below. If you have any > suggestions on how they

Re: PIL how to display multiple images side by side

2010-01-11 Thread suresh.amritapuri
On Jan 9, 9:51 pm, "Alf P. Steinbach" wrote: > * Lie Ryan: > > > On 1/9/2010 8:43 AM, suresh.amritapuri wrote: > >> Hi, > > >> In PIL, how to display multiple images in say m rows and n colums when > >> I have m*n images. > > >> suresh > > > Tkinter has PhotoImage widget and PIL has support for th

Re: What is built-in method sub

2010-01-11 Thread Diez B. Roggisch
Jeremy schrieb: On Jan 11, 12:54 pm, Carl Banks wrote: On Jan 11, 11:20 am, Jeremy wrote: I just profiled one of my Python scripts and discovered that >99% of the time was spent in {built-in method sub} What is this function and is there a way to optimize it? I'm guessing this is re.sub (or

Re: xml.sax parsing elements with the same name

2010-01-11 Thread amadain
On Jan 11, 7:26 pm, John Bokma wrote: > amadain writes: > > I have an event log with 100s of thousands of entries with logs of the > > form: > > > > uniqueId="1261124569.35725_PFS_1_1340035961"> > >     > >       > >           > >               > >                     > >               > >  

Re: lightweight encryption of text file

2010-01-11 Thread Anthra Norell
Robert Kern wrote: On 2010-01-09 03:52 AM, Anthra Norell wrote: Daniel Fetchinson wrote: > I have a plain text file which I would like to protect in a very > simple minded, yet for my purposes sufficient, way. I'd like to > encrypt/convert it into a binary file in such a way that possession

Re: pyserial: Unexpected Local Echo

2010-01-11 Thread Grant Edwards
On 2010-01-11, Steven Woody wrote: > I am using pyserial. But I always get the local echo after I > write some characters onto serial port I really doubt you're getting a local echo. Is the data coming out the serial port? Do you get the echo if you disconnect the serial cable? > and I find

Re: What is built-in method sub

2010-01-11 Thread Jeremy
On Jan 11, 12:54 pm, Carl Banks wrote: > On Jan 11, 11:20 am, Jeremy wrote: > > > I just profiled one of my Python scripts and discovered that >99% of > > the time was spent in > > > {built-in method sub} > > > What is this function and is there a way to optimize it? > > I'm guessing this is re.s

Re: Fundamental Function Question (beginner)

2010-01-11 Thread Philip Semanchuk
On Jan 11, 2010, at 2:50 PM, Phlip wrote: MRAB wrote: Scott wrote: for prtnmS in open(portfpth): prtnmS = prtnmS.rstrip() There's nothing wrong with building dicts or other lookup tables outside a function in order to avoid re-creating them every time the function is called. Ho

Re: What is built-in method sub

2010-01-11 Thread MRAB
Jeremy wrote: I just profiled one of my Python scripts and discovered that >99% of the time was spent in {built-in method sub} What is this function and is there a way to optimize it? I think it's the subtraction operator. The only way to optimise it is to reduce the number of subtractions th

Re: What is built-in method sub

2010-01-11 Thread Matthew Barnett
Jeremy wrote: I just profiled one of my Python scripts and discovered that >99% of the time was spent in {built-in method sub} What is this function and is there a way to optimize it? Thanks, Jeremy -- http://mail.python.org/mailman/listinfo/python-list

Re: What is built-in method sub

2010-01-11 Thread Carl Banks
On Jan 11, 11:20 am, Jeremy wrote: > I just profiled one of my Python scripts and discovered that >99% of > the time was spent in > > {built-in method sub} > > What is this function and is there a way to optimize it? I'm guessing this is re.sub (or, more likely, a method sub of an internal object

Re: Python Goldmine has been updated: http://preciseinfo.org/Convert/index_Convert_Python.html

2010-01-11 Thread tanix
In article , Steve Holden wrote: >Steve Holden wrote: >[...] >> Because I habitually run the NoScript extension to Firefox the popups >> didn't appear, but there didn't seem to be any original content on this >> site. Google continues to be your friend. >> >And dammit, why didn't I think to stri

Re: Python Goldmine has been updated: http://preciseinfo.org/Convert/index_Convert_Python.html

2010-01-11 Thread tanix
In article , Steve Holden wrote: >Terry Reedy wrote: >> On 1/8/2010 11:50 AM, tanix wrote: >>> Python Goldmine collection contains the extensive collection of articles >>> going back several years. It includes thousands of code >>> examples and expert discussions on all major topics. >>> >>> The

Re: Python Goldmine has been updated: http://preciseinfo.org/Convert/index_Convert_Python.html

2010-01-11 Thread tanix
In article , Terry Reedy wrote: >On 1/8/2010 11:50 AM, tanix wrote: >> Python Goldmine collection contains the extensive collection of articles >> going back several years. It includes thousands of code >> examples and expert discussions on all major topics. >> >> The information is organized by

Re: Fundamental Function Question (beginner)

2010-01-11 Thread Phlip
MRAB wrote: Scott wrote: for prtnmS in open(portfpth): prtnmS = prtnmS.rstrip() There's nothing wrong with building dicts or other lookup tables outside a function in order to avoid re-creating them every time the function is called. However, please consider writing complete, pronoun

Re: xml.sax parsing elements with the same name

2010-01-11 Thread John Bokma
amadain writes: > I have an event log with 100s of thousands of entries with logs of the > form: > > uniqueId="1261124569.35725_PFS_1_1340035961"> > > > > > > > > > >

What is built-in method sub

2010-01-11 Thread Jeremy
I just profiled one of my Python scripts and discovered that >99% of the time was spent in {built-in method sub} What is this function and is there a way to optimize it? Thanks, Jeremy -- http://mail.python.org/mailman/listinfo/python-list

Re: Different number of matches from re.findall and re.split

2010-01-11 Thread Jeremy
On Jan 11, 9:28 am, Duncan Booth wrote: > MRAB wrote: > >> Yep.  Thanks for pointing that out.  I guess I just assumed that > >> re.split was similar to re.search/match/findall in what it accepted as > >> function parameters.  I guess I'll have to use a \n instead of a ^ for > >> split. > > > You

Re: Fundamental Function Question (beginner)

2010-01-11 Thread r0g
r0g wrote: > Scott wrote: >> When creating a function is there any difference between putting >> everything under the "def" or not? >> >> Here I created a function called CscoPortNum to convert the network >> port number field in a Cisco syslog string from a an ascii name back >> into its numeric f

xml.sax parsing elements with the same name

2010-01-11 Thread amadain
I have an event log with 100s of thousands of entries with logs of the form: I am using xml.sax to parse the event log. The trouble w

Re: integer and string compare, is that correct?

2010-01-11 Thread Arnaud Delobelle
Nobody writes: > On Sun, 10 Jan 2010 23:13:55 -0800, Dan Bishop wrote: > >>> If you actually need to perform comparisons across types, you can rely >>> upon the fact that tuple comparisons are non-strict and use e.g.: >>> >>>         > a = 5 >>>         > b = '5' >>>         > (type(a).__name__,

Re: Interesting (?) problem

2010-01-11 Thread Nobody
On Mon, 11 Jan 2010 18:57:24 +0100, mk wrote: >> I have two lists of IP addresses: >> >> hostips = [ 'a', 'b', 'c', 'd', 'e' ] >> >> thread_results = [ 'd', 'b', 'c' ] >> >> I need to sort thread_results in the same order as hostips. > > P.S. One clarification: those lists are actually more co

Re: Different number of matches from re.findall and re.split

2010-01-11 Thread Steve Holden
Jeremy wrote: > On Jan 11, 8:44 am, Iain King wrote: >> On Jan 11, 3:35 pm, Jeremy wrote: >> >> >> >> >> >>> Hello all, >>> I am using re.split to separate some text into logical structures. >>> The trouble is that re.split doesn't find everything while re.findall >>> does; i.e.: found = re.

Re: Fundamental Function Question (beginner)

2010-01-11 Thread r0g
Scott wrote: > When creating a function is there any difference between putting > everything under the "def" or not? > > Here I created a function called CscoPortNum to convert the network > port number field in a Cisco syslog string from a an ascii name back > into its numeric form if required. D

Re: pyserial: Unexpected Local Echo

2010-01-11 Thread Nobody
On Mon, 11 Jan 2010 23:27:03 +0800, Steven Woody wrote: > I am using pyserial. But I always get the local echo after I write > some characters onto serial port and I find no way to disable this > behavior. When I say 'local echo', I mean the next read operation will > get characters that was just

Re: Fundamental Function Question (beginner)

2010-01-11 Thread MRAB
Scott wrote: When creating a function is there any difference between putting everything under the "def" or not? Here I created a function called CscoPortNum to convert the network port number field in a Cisco syslog string from a an ascii name back into its numeric form if required. Does it mat

Re: C Module's '1.#INF' changes to 'inf' at Python

2010-01-11 Thread Robert Kern
On 2010-01-11 12:27 PM, CELEN Erman wrote: Numeric.log10() will check to see if the errno was set to ERANGE. It does not check if a floating point exception flag was set, which is tricky to do across platforms. The newer numpy can do it because we've finally managed to implement all of that platf

Re: sys.stdout vs. sys.stderr

2010-01-11 Thread Nobody
On Mon, 11 Jan 2010 10:09:36 +0100, Martin v. Loewis wrote: >> In Python 3.1 is there any difference in the buffering behavior of the >> initial sys.stdout and sys.stderr streams? > > No. > >> Were they different at some earlier point in Python's evolution? > > That depends on the operating sys

Re: Interesting (?) problem

2010-01-11 Thread Paul Rubin
mk writes: > I have two lists of IP addresses: > > hostips = [ 'a', 'b', 'c', 'd', 'e' ] > > thread_results = [ 'd', 'b', 'c' ] > > I need to sort thread_results in the same order as hostips. Assuming each address in hostips appears just once: from itertools import izip,count d = dict(iz

Re: integer and string compare, is that correct?

2010-01-11 Thread Nobody
On Sun, 10 Jan 2010 23:13:55 -0800, Dan Bishop wrote: >> If you actually need to perform comparisons across types, you can rely >> upon the fact that tuple comparisons are non-strict and use e.g.: >> >>         > a = 5 >>         > b = '5' >>         > (type(a).__name__, a) < (type(b).__name__, b)

Re: Interesting (?) problem

2010-01-11 Thread Peter Otten
mk wrote: > mk wrote: >> Hello everyone, >> >> I have two lists of IP addresses: >> >> hostips = [ 'a', 'b', 'c', 'd', 'e' ] >> >> thread_results = [ 'd', 'b', 'c' ] >> >> I need to sort thread_results in the same order as hostips. > > P.S. One clarification: those lists are actually more com

Fundamental Function Question (beginner)

2010-01-11 Thread Scott
When creating a function is there any difference between putting everything under the "def" or not? Here I created a function called CscoPortNum to convert the network port number field in a Cisco syslog string from a an ascii name back into its numeric form if required. Does it matter at all that

Re: Interesting (?) problem

2010-01-11 Thread Jean-Michel Pichavant
mk wrote: mk wrote: Hello everyone, I have two lists of IP addresses: hostips = [ 'a', 'b', 'c', 'd', 'e' ] thread_results = [ 'd', 'b', 'c' ] I need to sort thread_results in the same order as hostips. P.S. One clarification: those lists are actually more complicated (thread_result is a

RE: C Module's '1.#INF' changes to 'inf' at Python

2010-01-11 Thread CELEN Erman
> Numeric.log10() will check to see if the errno was set to ERANGE. It does not > check if a floating point exception flag was set, which is tricky to do > across > platforms. The newer numpy can do it because we've finally managed to > implement > all of that platform-specific code, but the e

Re: Interesting (?) problem

2010-01-11 Thread Arnaud Delobelle
mk writes: > Hello everyone, > > I have two lists of IP addresses: > > hostips = [ 'a', 'b', 'c', 'd', 'e' ] > > thread_results = [ 'd', 'b', 'c' ] > > I need to sort thread_results in the same order as hostips. [...solution:] > hostips_limited = [] > for h in hostips: > if h in thread_resul

Re: Interesting (?) problem

2010-01-11 Thread mk
mk wrote: Hello everyone, I have two lists of IP addresses: hostips = [ 'a', 'b', 'c', 'd', 'e' ] thread_results = [ 'd', 'b', 'c' ] I need to sort thread_results in the same order as hostips. P.S. One clarification: those lists are actually more complicated (thread_result is a list of tup

Re: Interesting (?) problem

2010-01-11 Thread Jean-Michel Pichavant
mk wrote: Incidentally, it *seems* that list comprehension preserves order: hostips_limited = [ h for h in hostips if h in thread_results ] Empirically speaking it seems to work (I tested it on real ips), but please correct me if that's wrong. Regards, mk Sounds good to me. List are *o

Interesting (?) problem

2010-01-11 Thread mk
Hello everyone, I have two lists of IP addresses: hostips = [ 'a', 'b', 'c', 'd', 'e' ] thread_results = [ 'd', 'b', 'c' ] I need to sort thread_results in the same order as hostips. (Obviously, hostips can contain any valid ip addresses as strings, they are sorted alphabetically here just f

Re: Procedural API inside class--scoping questions

2010-01-11 Thread Bruno Desthuilliers
Kevin Walzer a écrit : I'm trying to make use of a Python library, aemreceive, that provides a procedural API. (aemreceive is a library for Python on the Mac that allows the application to receive and respond to Apple Events.) My Python apps basically run in a single fooApp class, and everythi

Re: Fractional Hours from datetime?

2010-01-11 Thread W. eWatson
Austyn wrote: Here's an improvement in case you want your code to work outside of Arizona: from time import time, timezone h = ((time() - timezone) / 3600) % 24 On Jan 10, 9:04 pm, Austyn wrote: How about: import time arizona_utc_offset = -7.00 h = (time.time() / 3600 + arizona_utc_offset) %

  1   2   >