Tips on Speeding up Python Execution

2011-04-08 Thread Abhijeet Mahagaonkar
Dear Pythoners, I have written a python application which authenticates a user, reads a webpage and searches for pattern and builds a database ( In my case its a dictinary with fixed set of keys). Inputting the username and password for authentication and final display of the results is done by GUI

Re: How to re import a module

2011-04-08 Thread Rafael Durán Castañeda
That's really easy: >>> import re >>> reload(re) >>> In python2.x, but if you are using python3.x I think is different, really easy to know if you search in python docs. 2011/4/8 > Hello i want to know the best way to re import a module, because i have a > web server with just one Apache sess

Re: Amazon Simple Queue Service Worker

2011-04-08 Thread Joseph Ziegler
Thanks! On 7 April 2011 10:13, Joseph Ziegler wrote: > Hi all, > > Little new to the python world, please excuse the Noobness. > > We are writing a server which will subscribe to the Amazon Simple Queue > Service. I am looking for a good service container. I saw Twisted and Zope > out there. I

Re: Tips on Speeding up Python Execution

2011-04-08 Thread Chris Angelico
On Fri, Apr 8, 2011 at 5:04 PM, Abhijeet Mahagaonkar wrote: > I was able to isolate that major chunk of run time is eaten up in opening a > webpages, reading from them and extracting text. > I wanted to know if there is a way to concurrently calling the functions. So, to clarify: you have code th

Re: Literate Programming

2011-04-08 Thread Hans Georg Schaathun
On Thu, 07 Apr 2011 16:21:52 -0500, Robert Kern wrote: : http://sphinx.pocoo.org/markup/code.html : : As far as I can tell, it just works. See here for an example: : : http://ipython.scipy.org/doc/nightly/html/interactive/reference.html Maybe I did not express myself clearly. I don't have

see the link

2011-04-08 Thread ramalingam i
webpage : http://123maza.com/65/hand741/ -- http://mail.python.org/mailman/listinfo/python-list

How to get a PID of a child process from a process openden with Popen()

2011-04-08 Thread P.S.
Hello, I am starting a GUI-application as another user with kdesu in my python script: import shlex, subprocess p = subprocess.Popen(shlex.split("kdesu -u test program")) How can I aquire the PID of the program which kdesu starts? p.pid just returns the PID of kdesu, but I need

3.2: email.message.get_payload() delivers str, but send_message expect bytes

2011-04-08 Thread Axel Rau
Hi all, I'm just starting with imaplib, email and smtplib and try to write a SPAM reporter. I retrieve SPAM mails from an IMAP server and add them as message/rfc822 attachments to a report mail. Sometimes my call of smtplib.send_message works, sometimes, I get: -- File "/Library/Framewor

NLP

2011-04-08 Thread Ranjith Kumar
Hi all, Can anyone suggest me any best Natural Language Processing in python other than nltk. -- Cheers, Ranjith Kumar K, Chennai. http://ranjithtenz.wordpress.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Literate Programming

2011-04-08 Thread Jim
On Apr 7, 2:09 pm, Hans Georg Schaathun wrote: > Has anyone found a good system for literate programming in python? Are you aware of pyweb http://sourceforge.net/projects/pywebtool/ ? -- http://mail.python.org/mailman/listinfo/python-list

[2.5.1] Script to download and rename bunch of files?

2011-04-08 Thread Gilles Ganault
Hello, Before I go ahead and learn how to write this, I was wondering if someone knew of some source code I could use to download and rename a bunch of files, ie. the equivalent of wget's -O switch? I would provide a two-column list where column 1 would contain the full URL, and column 2

Re: [2.5.1] Script to download and rename bunch of files?

2011-04-08 Thread Laurent Claessens
Le 08/04/2011 14:47, Gilles Ganault a écrit : Hello, Before I go ahead and learn how to write this, I was wondering if someone knew of some source code I could use to download and rename a bunch of files, ie. the equivalent of wget's -O switch? I would provide a two-column list where co

Re: [2.5.1] Script to download and rename bunch of files?

2011-04-08 Thread Gilles Ganault
On Fri, 08 Apr 2011 15:14:27 +0200, Laurent Claessens wrote: >The following puts in the string `a` the code of the page urlBase : > >a = urllib.urlopen(urlBase).read() > >Then you have to write `a` in a file. > >There could be better way. Thank you. -- http://mail.python.org/mailman/listinfo/pyt

Re: [OT] Free software versus software idea patents

2011-04-08 Thread Westley Martínez
On Fri, 2011-04-08 at 01:41 -0500, harrismh777 wrote: > Steven D'Aprano wrote: > > Just like Python, Apache, and the Linux kernel. What are you going to do > > to punish them? > > What do you mean 'just like"?They are nothing alike. > > (which is why the community is upset by sone, but no

Re: Fun python 3.2 one-liner

2011-04-08 Thread Lie Ryan
On 04/06/11 01:07, Steven D'Aprano wrote: > On Tue, 05 Apr 2011 15:38:28 +0200, Daniel Fetchinson wrote: > Personally, I find that the discipline of keeping to 80 characters is > good for me. It reduces the temptation of writing obfuscated Python one- > liners when two lines would be better. The

Re: Tips on Speeding up Python Execution

2011-04-08 Thread MRAB
On 08/04/2011 08:25, Chris Angelico wrote: [snip] I don't know what's the most Pythonesque option, but if you already have specific Python code for each of your functions, it's probably going to be easiest to spawn threads for them all. "Pythonesque" refers to "Monty Python's Flying Circus". Th

Re: How to get a PID of a child process from a process openden with Popen()

2011-04-08 Thread Miki Tebeka
> p = subprocess.Popen(shlex.split("kdesu -u test program")) > > How can I aquire the PID of the program which kdesu starts? You can run "ps --ppid " and get the line containing test program. The first field there should be the child process id. HTH -- Miki Tebeka http://pythonwise.blogspo

Re: Guido rethinking removal of cmp from sort method

2011-04-08 Thread Aahz
In article <4d8be3bb.4030...@v.loewis.de>, Martin v. Loewis wrote: >Martin deleted the attribution for Carl Banks: >> >> The cmp argument doesn't depend in any way on an object's __cmp__ >> method, so getting rid of __cmp__ wasn't any good readon to also get >> rid of the cmp argument > >So what d

Python 3.2 vs Java 1.6

2011-04-08 Thread km
Hi All, How does python 3.2 fare compared to Java 1.6 in terms of performance ? any pointers or observations ? regards, KM -- http://mail.python.org/mailman/listinfo/python-list

Re: Tips on Speeding up Python Execution

2011-04-08 Thread Chris Angelico
On Sat, Apr 9, 2011 at 12:41 AM, MRAB wrote: > On 08/04/2011 08:25, Chris Angelico wrote: > [snip] >> >> I don't know what's the most Pythonesque option, but if you already >> have specific Python code for each of your functions, it's probably >> going to be easiest to spawn threads for them all.

Re: Python 3.2 vs Java 1.6

2011-04-08 Thread Chris Angelico
On Sat, Apr 9, 2011 at 1:21 AM, km wrote: > Hi All, > > How does python 3.2 fare compared to Java 1.6 in terms of performance ? > any pointers or observations ? Hi All, How do apples compare to oranges in terms of performance? Chris Angelico -- http://mail.python.org/mailman/listinfo/python-li

Re: Python 3.2 vs Java 1.6

2011-04-08 Thread Moises Alberto Lindo Gutarra
I work with java since 1997 and with python three years ago, and i really think that python performance is much better than java, i made same applications using both and python always responses better. Try to do the same with a little appication accesing data bases, using ftp clients, etc and you w

Re: Tips on Speeding up Python Execution

2011-04-08 Thread Matt Chaput
On 08/04/2011 11:31 AM, Chris Angelico wrote: On Sat, Apr 9, 2011 at 12:41 AM, MRAB wrote: On 08/04/2011 08:25, Chris Angelico wrote: [snip] I don't know what's the most Pythonesque option, but if you already have specific Python code for each of your functions, it's probably going to be easi

Generators and propagation of exceptions

2011-04-08 Thread r
I had a problem for which I've already found a "satisfactory" work-around, but I'd like to ask you if there is a better/nicer looking solution. Perhaps I'm missing something obvious. The code looks like this: stream-of-tokens = token-generator(stream-of-characters) stream-of-parsed-expressions =

Re: [OT] Free software versus software idea patents

2011-04-08 Thread Ethan Furman
Westley Martínez wrote: On Fri, 2011-04-08 at 01:41 -0500, harrismh777 wrote: Freedom isn't free... you have to fight for it... always. Why should a business listen to you? You're not gonna buy any software anyways. From a thread a few months back I can say there are a couple companies wi

Re: Guido rethinking removal of cmp from sort method

2011-04-08 Thread Lie Ryan
On 04/09/11 01:08, Aahz wrote: > Actually, my take is that removing __cmp__ was a mistake. (I already > argued about it back in python-dev before it happened, and I see little > point rehashing it. My reason is strictly efficiency grounds: when > comparisons are expensive -- such as Decimal objec

Copy-on-write when forking a python process

2011-04-08 Thread John Connor
Hi all, Long time reader, first time poster. I am wondering if anything can be done about the COW (copy-on-write) problem when forking a python process. I have found several discussions of this problem, but I have seen no proposed solutions or workarounds. My understanding of the problem is that

Re: Generators and propagation of exceptions

2011-04-08 Thread Ian Kelly
On Fri, Apr 8, 2011 at 9:55 AM, r wrote: > I had a problem for which I've already found a "satisfactory" > work-around, but I'd like to ask you if there is a better/nicer > looking solution. Perhaps I'm missing something obvious. > > The code looks like this: > > stream-of-tokens = token-generator

Argument of the bool function

2011-04-08 Thread candide
About the standard function bool(), Python's official documentation tells us the following : bool([x]) Convert a value to a Boolean, using the standard truth testing procedure. In this context, what exactly a "value" is referring to ? For instance, >>> x=42 >>> bool(x=5) True >>> but _ex

Re: Generators and propagation of exceptions

2011-04-08 Thread Terry Reedy
On 4/8/2011 11:55 AM, r wrote: I had a problem for which I've already found a "satisfactory" work-around, but I'd like to ask you if there is a better/nicer looking solution. Perhaps I'm missing something obvious. The code looks like this: stream-of-tokens = token-generator(stream-of-characters

Re: Argument of the bool function

2011-04-08 Thread Benjamin Kaplan
On Fri, Apr 8, 2011 at 12:26 PM, candide wrote: > About the standard function bool(), Python's official documentation tells us > the following : > > bool([x]) > Convert a value to a Boolean, using the standard truth testing procedure. > > > In this context, what exactly a "value" is referring to ?

Re: Argument of the bool function

2011-04-08 Thread Ian Kelly
On Fri, Apr 8, 2011 at 10:26 AM, candide wrote: x=42 bool(x=5) > True > > > but _expression_ : > > x=42 > > > has no value. "x=42" is an assignment statement, not an expression. In "bool(x=5)", "x=5" is also not an expression. It's passing the expression "5" in as the parameter x,

Re: Argument of the bool function

2011-04-08 Thread Mel
candide wrote: > About the standard function bool(), Python's official documentation > tells us the following : > > bool([x]) > Convert a value to a Boolean, using the standard truth testing procedure. > > In this context, what exactly a "value" is referring to ? > > For instance, > >>> x=42 > >

Re: Copy-on-write when forking a python process

2011-04-08 Thread Heiko Wundram
Am 08.04.2011 18:14, schrieb John Connor: > Has anyone else looked into the COW problem? Are there workarounds > and/or other plans to fix it? Does the solution I am proposing sound > reasonable, or does it seem like overkill? Does anyone foresee any > problems with it? Why'd you need a "fix" l

Re: Tips on Speeding up Python Execution

2011-04-08 Thread Raymond Hettinger
On Apr 8, 12:25 am, Chris Angelico wrote: > On Fri, Apr 8, 2011 at 5:04 PM, Abhijeet Mahagaonkar > > wrote: > > I was able to isolate that major chunk of run time is eaten up in opening a > > webpages, reading from them and extracting text. > > I wanted to know if there is a way to concurrently c

Re: Python 3.2 vs Java 1.6

2011-04-08 Thread geremy condra
On Fri, Apr 8, 2011 at 8:21 AM, km wrote: > Hi All, > > How does python 3.2 fare compared to Java 1.6 in terms of performance ? > any pointers or observations ? Python and Java have overall very different performance profiles, but for the vast majority of applications either will suffice. If you

Re: Generators and propagation of exceptions

2011-04-08 Thread Raymond Hettinger
On Apr 8, 8:55 am, r wrote: > I had a problem for which I've already found a "satisfactory" > work-around, but I'd like to ask you if there is a better/nicer > looking solution. Perhaps I'm missing something obvious. > > The code looks like this: > > stream-of-tokens = token-generator(stream-of-ch

argparse and default for FileType

2011-04-08 Thread Paolo Elvati
Hi, I noticed a "strange" behavior of argparse. When running a simple code like the following: import argparse parser = argparse.ArgumentParser() parser.add_argument( "-o", default = 'fake', dest = 'OutputFile', type = argparse.FileType('w') ) args = parser.parse_args() I noticed that t

Re: Generators and propagation of exceptions

2011-04-08 Thread r
Terry, Ian, thank you for your answers. On Sat, Apr 9, 2011 at 1:30 AM, Terry Reedy wrote: [...] > According to the above, that should be stream-of-parsed-expressions. Good catch. > The question which you do not answer below is what, if anything, you want to > do with error? If nothing, just pa

Re: Generators and propagation of exceptions

2011-04-08 Thread Raymond Hettinger
On Apr 8, 8:55 am, r wrote: > I had a problem for which I've already found a "satisfactory" > work-around, but I'd like to ask you if there is a better/nicer > looking solution. Perhaps I'm missing something obvious. > > The code looks like this: > > stream-of-tokens = token-generator(stream-of-ch

Re: Generators and propagation of exceptions

2011-04-08 Thread Ethan Furman
r wrote: The code above implements an interactive session (a REPL). Therefore, what I'd like to get is an error information printed out at the output as soon as it becomes available. Couple ideas: 1) Instead of yielding the error, call some global print function, then continue on; or 2) Col

Re: Copy-on-write when forking a python process

2011-04-08 Thread jac
Hi Heiko, I just realized I should probably have put a clearer use-case in my previous message. A example use-case would be if you have a parent process which creates a large dictionary (say several gigabytes). The process then forks several worker processes which access this dictionary. The wor

Creating unit tests on the fly

2011-04-08 Thread Roy Smith
I've got a suite of unit tests for a web application. There's an (abstract) base test class from which all test cases derive: class BaseSmokeTest(unittest.TestCase): BaseSmokeTest.setUpClass() fetches a UR (from a class attribute "route", which must be defined in the derived classes), and there'

Re: Literate Programming

2011-04-08 Thread Hans Georg Schaathun
On Fri, 8 Apr 2011 05:22:01 -0700 (PDT), Jim wrote: : On Apr 7, 2:09 pm, Hans Georg Schaathun wrote: : > Has anyone found a good system for literate programming in python? : : Are you aware of pyweb http://sourceforge.net/projects/pywebtool/ ? Interesting tool, but it solves only part of th

Re: How to get a PID of a child process from a process openden with Popen()

2011-04-08 Thread Nobody
On Fri, 08 Apr 2011 07:43:41 -0700, Miki Tebeka wrote: >> p = subprocess.Popen(shlex.split("kdesu -u test program")) >> >> How can I aquire the PID of the program which kdesu starts? > > You can run "ps --ppid " and get the line containing test program. > The first field there should be the

Re: Guido rethinking removal of cmp from sort method

2011-04-08 Thread Aahz
In article <4d9f32a2$1...@dnews.tpgi.com.au>, Lie Ryan wrote: >On 04/09/11 01:08, Aahz wrote: >> >> Actually, my take is that removing __cmp__ was a mistake. (I already >> argued about it back in python-dev before it happened, and I see little >> point rehashing it. My reason is strictly effici

Re: Generators and propagation of exceptions

2011-04-08 Thread r
On Sat, Apr 9, 2011 at 3:22 AM, Raymond Hettinger wrote: > > You could just let the exception go up to an outermost control-loop > without handling it at all on a lower level.  That is what exceptions > for you: terminate all the loops, unwind the stacks, and propagate up > to some level where the

Re: argparse and default for FileType

2011-04-08 Thread Robert Kern
On 4/8/11 1:11 PM, Paolo Elvati wrote: Hi, I noticed a "strange" behavior of argparse. When running a simple code like the following: import argparse parser = argparse.ArgumentParser() parser.add_argument( "-o", default = 'fake', dest = 'OutputFile', type = argparse.FileType('w')

Re: Generators and propagation of exceptions

2011-04-08 Thread Raymond Hettinger
On Apr 8, 12:47 pm, r wrote: > Anyway, thank you all for helping me out and bringing some ideas to > the table. I was hoping there might be some pattern specifically > designed for thiskind of job (exception generators anyone?), which > I've overlooked. If not anything else, knowing that this isn'

Re: Copy-on-write when forking a python process

2011-04-08 Thread Heiko Wundram
Am 08.04.2011 20:34, schrieb jac: > I disagree with your statement that COW is an optimization for a > complete clone, it is an optimization that works at the memory page > level, not at the memory image level. In other words, if I write to a > copy-on-write page, only that page is copied into my

Re: Argument of the bool function

2011-04-08 Thread candide
Le 08/04/2011 18:43, Ian Kelly a écrit : "x=42" is an assignment statement, not an expression. Right, I was confounding with C ;) In fact, respect to this question, the documentation makes things unambiguous : - In contrast to many other languages, not all language constru

Re: Argument of the bool function

2011-04-08 Thread Ethan Furman
candide wrote: Le 08/04/2011 18:43, Ian Kelly a écrit : In "bool(x=5)", "x=5" is also not an expression. It's passing the expression "5" in as the parameter x, using a keyword argument. >> You are probably right but how do you deduce this brilliant interpretation from the wording given in th

Re: Creating unit tests on the fly

2011-04-08 Thread Raymond Hettinger
On Apr 8, 12:10 pm, Roy Smith wrote: > I can even create new test cases from these on the fly with something > like: > >  newClass = type("newClass", (BaseSmokeTest,), {'route': '/my/newly/ > discovered/anchor'}) > > (credit > tohttp://jjinux.blogspot.com/2005/03/python-create-new-class-on-fly.ht

Re: How to use optparse without the command line?

2011-04-08 Thread Karim
On 04/07/2011 10:37 AM, markolopa wrote: Hello, Is there support/idioms/suggestions for using optparse without a command line? I have a code which used to be called through subprocess. The whole flow of the code is based on what 'options' object from optparse contains. Now I want to call this

Re: Argument of the bool function

2011-04-08 Thread Ben Finney
candide writes: > Le 08/04/2011 18:43, Ian Kelly a écrit : > > In "bool(x=5)", "x=5" is also not an expression. It's passing the > > expression "5" in as the parameter x, using a keyword argument. > > You are probably right but how do you deduce this brilliant > interpretation from the wording g

Re: How to get a PID of a child process from a process openden with Popen()

2011-04-08 Thread Chris Angelico
On Sat, Apr 9, 2011 at 5:28 AM, Nobody wrote: > There isn't a robust solution to the OP's problem. It's typically > impossible to determine whether one process is an ancestor of another if > any of the intermediate processes have terminated. Upstart and gdb can both detect forks and follow the ch

Re: using python to post data to a form

2011-04-08 Thread Karim
On 04/04/2011 01:01 PM, Corey Richardson wrote: On 04/04/2011 01:36 AM, Littlefield, Tyler wrote: Hello: I have some data that needs to be fed through a html form to get validated and processed and the like. How can I use python to send data through that form, given a specific url? the form says

Re: Creating unit tests on the fly

2011-04-08 Thread Ben Finney
Raymond Hettinger writes: > I think you're going to need a queue of tests, with your own test > runner consuming the queue, and your on-the-fly test creator running > as a producer thread. I have found the ‘testscenarios’ library very useful for this: bind a sequence of (name, dict) tuples to th

Re: Argument of the bool function

2011-04-08 Thread candide
Le 09/04/2011 00:03, Ethan Furman a écrit : > bool([x]) > Convert a value to a Boolean, using the standard truth testing > procedure. > As you can see, the parameter name is 'x'. OK, your response is clarifying my point ;) I didn't realize that in the bool([x]) syntax, identifier x ref

Re: Tips on Speeding up Python Execution

2011-04-08 Thread Abhijeet Mahagaonkar
Thats awesome. Its time I migrate to 3 :) On Fri, Apr 8, 2011 at 11:29 PM, Raymond Hettinger wrote: > On Apr 8, 12:25 am, Chris Angelico wrote: > > On Fri, Apr 8, 2011 at 5:04 PM, Abhijeet Mahagaonkar > > > > wrote: > > > I was able to isolate that major chunk of run time is eaten up in > open

Re: Creating unit tests on the fly

2011-04-08 Thread Roy Smith
In article <87fwpse4zt@benfinney.id.au>, Ben Finney wrote: > Raymond Hettinger writes: > > > I think you're going to need a queue of tests, with your own test > > runner consuming the queue, and your on-the-fly test creator running > > as a producer thread. > > I have found the ‘testsce

Re: Creating unit tests on the fly

2011-04-08 Thread Ben Finney
Roy Smith writes: > In article <87fwpse4zt@benfinney.id.au>, > Ben Finney wrote: > > > I have found the ‘testscenarios’ library very useful for this: > > bind a sequence of (name, dict) tuples to the test case class, and > > each tuple represents a scenario of data fixtures that will be

Re: Literate Programming

2011-04-08 Thread Tim Arnold
"Hans Georg Schaathun" wrote in message news:r7b178-602@svn.schaathun.net... > Has anyone found a good system for literate programming in python? > > I have been trying to use pylit/sphinx/pdflatex to generate > technical documentation. The application is scientific/numerical > programming,

python on iPad (PyPad)

2011-04-08 Thread Jon Dowdall
Hi All, Sorry for the blatant advertising but hope some of you may be interested to know that I've created an iPad application containing the python interpreter and a simple execution environment. It's available in iTunes at http://itunes.apple.com/us/app/pypad/id428928902?mt=8# I wanted to ha

Re: Argument of the bool function

2011-04-08 Thread Lie Ryan
On 04/09/11 08:59, candide wrote: > Le 09/04/2011 00:03, Ethan Furman a écrit : > >> > bool([x]) >> > Convert a value to a Boolean, using the standard truth testing >> > procedure. >> > >> >> As you can see, the parameter name is 'x'. > > > OK, your response is clarifying my point ;) > > >

Re: python on iPad (PyPad)

2011-04-08 Thread Eric Snow
On Fri, Apr 8, 2011 at 11:13 PM, Jon Dowdall wrote: > Hi All, > > Sorry for the blatant advertising but hope some of you may be interested > to know that I've created an iPad application containing the python > interpreter and a simple execution environment. It's available in iTunes > at http://it

Re: Python 3.2 vs Java 1.6

2011-04-08 Thread Steven D'Aprano
On Sat, 09 Apr 2011 01:32:17 +1000, Chris Angelico wrote: > On Sat, Apr 9, 2011 at 1:21 AM, km wrote: >> Hi All, >> >> How does python 3.2 fare compared to Java 1.6 in terms of performance ? >> any pointers or observations ? > > Hi All, > > How do apples compare to oranges in terms of performan

Re: [OT] Free software versus software idea patents

2011-04-08 Thread Bob Martin
in 654905 20110408 171055 Ethan Furman wrote: >Westley Mart�nez wrote: >> On Fri, 2011-04-08 at 01:41 -0500, harrismh777 wrote: >>> >>> Freedom isn't free... you have to fight for it... always. >> >> Why should a business listen to you? You're no