Re: Speed-up for loops

2010-09-02 Thread Ulrich Eckhardt
Tim Wintle wrote: > [..] under the hood, cpython does something like this (in psudo-code) > > itterator = xrange(imax) > while 1: > next_attribute = itterator.next > try: > i = next_attribute() > except: > break > a = a + 10 There is one thing that strikes me here: The code claims

Re: killing all subprocess childrens

2010-09-02 Thread Lawrence D'Oliveiro
In message , Astan Chee wrote: > What I'm trying to do (and wondering if its possible) is to make sure > that any children (and any descendants) of this process is killed when > the main java process is killed (or dies). > How do I do this in windows, linux and OSX? A linux-specific solution cou

Re: Obscure MySQLdb question - duplicating a database handle

2010-09-02 Thread Lawrence D'Oliveiro
In message <4c801218$0$1622$742ec...@news.sonic.net>, John Nagle wrote: > The problem is that I want errorlog to commit its message to > the table used for error logging, but don't want to commit > whatever the caller was doing - that may well revert. Any particular reason you’re using a database

python database

2010-09-02 Thread shai garcia
can you pls help me to make a database program in python? It is a Quiz system which is database driven. The program has a choices which add question, edit, delete, list, take a quiz, quiz results, and exit. in take a quiz choice,questions should be randomly displayed and the result and name of t

python database

2010-09-02 Thread shai garcia
can you pls help me to make a database program in python? It is a Quiz system which is database driven. The program has a choices which add question, edit, delete, list, take a quiz, quiz results, and exit. in take a quiz choice,questions should be randomly displayed and the result and name of t

Re: Performance: sets vs dicts.

2010-09-02 Thread Arnaud Delobelle
Terry Reedy writes: > On 9/1/2010 8:11 PM, John Bokma wrote: [...] Uhm, O(1) /is/ constant time, see page 45 of Introduction to Algorithms, 2nd edition. > > Given that the Wikipedia article references that section also, I > wonder if it really disagrees with the definition above. In si

Re: PyPy and RPython

2010-09-02 Thread sarvi
On Sep 2, 2:19 pm, John Nagle wrote: > On 9/2/2010 1:29 AM, sarvi wrote: > > > When I think about it these restrictions below seem a very reasonable > > tradeoff for performance. > >     Yes. > > > And I can use this for just the modules/sections that are performance > > critical. > >     Not quit

Does MySQLdb rollback on control-C? Maybe not.

2010-09-02 Thread John Nagle
I would expect MySQLdb to rollback on a control-C, but it doesn't seem to have done so. I have a program which does a thousand or so INSERT operations in one transaction on an InnoDB table. I kill it with a control-C on Windows, and it aborts. But it looks like some of the INSERT operatio

Re: Windows vs. file.read

2010-09-02 Thread Lawrence D'Oliveiro
In message , MRAB wrote: > On 02/09/2010 08:49, Lawrence D'Oliveiro wrote: >> In message, MRAB >> wrote: >> >>> You should open the files in binary mode, not text mode, ie file(path, >>> "rb"). Text mode is the default. Not a problem on *nix because the line >>> ending is newline. >> >> We used t

Re: DeprecationWarning

2010-09-02 Thread cerr
On Sep 2, 4:25 pm, Chris Rebert wrote: > On Thu, Sep 2, 2010 at 4:19 PM, cerr wrote: > > On Sep 1, 5:04 pm, Chris Rebert wrote: > >> On Wed, Sep 1, 2010 at 8:58 AM, cerr wrote: > >> > Hi There, > > >> > I would like to create an scp handle and download a file from a > >> > client. I have follow

Re: Re: Financial time series data

2010-09-02 Thread hidura
I've tried to see the page and the code GSPC it's wrong i has used ^DJI, and when you download the page code use a xml parser localize the table element and read it. I can't access from the browser to the next page it doesn't appear as a link. El , Virgil Stokes escribió: On 09/02/2010 08:

Re: Financial time series data

2010-09-02 Thread MRAB
On 03/09/2010 00:56, Virgil Stokes wrote: On 09/02/2010 08:15 PM, Hidura wrote: But what kind of data you want to download?, because the financial time it's basicly html code and you can work very well with a parser 2010/9/2, Virgil Stokes: Has anyone written code or worked with Python softwar

Re: Help needed with Windows Service in Python

2010-09-02 Thread Mark Hammond
On 3/09/2010 1:22 AM, Ian Hobson wrote: Hi All, I am attempting to create a Windows Service in Python. I have the framework (from Mark Hammond and Andy Robinason's book) running - see below. It starts fine - but it will not stop. :( net stop "Python Service" and using the services GUI both le

Re: Financial time series data

2010-09-02 Thread Virgil Stokes
On 09/02/2010 08:15 PM, Hidura wrote: But what kind of data you want to download?, because the financial time it's basicly html code and you can work very well with a parser 2010/9/2, Virgil Stokes: Has anyone written code or worked with Python software for downloading financial time ser

Re: DeprecationWarning

2010-09-02 Thread Chris Rebert
On Thu, Sep 2, 2010 at 4:19 PM, cerr wrote: > On Sep 1, 5:04 pm, Chris Rebert wrote: >> On Wed, Sep 1, 2010 at 8:58 AM, cerr wrote: >> > Hi There, >> >> > I would like to create an scp handle and download a file from a >> > client. I have following code: >> >> > but what i'm getting is this and

Re: Selecting k smallest or largest elements from a large list in python; (benchmarking)

2010-09-02 Thread Dmitry Chichkov
Yes, you are right of course. But it is not really a contest. And if you could improve algorithm or implementation on "your Python version running under your OS on your hardware" it may as well improve performance for other people under other OS's. On Sep 2, 3:14 pm, Terry Reedy wrote: > On 9/1/

Re: DeprecationWarning

2010-09-02 Thread cerr
On Sep 1, 5:04 pm, Chris Rebert wrote: > On Wed, Sep 1, 2010 at 8:58 AM, cerr wrote: > > Hi There, > > > I would like to create an scp handle and download a file from a > > client. I have following code: > > > but what i'm getting is this and no file is downloaded...: > > /opt/lampp/cgi-bin/atta

Re: Obscure MySQLdb question - duplicating a database handle

2010-09-02 Thread John Bokma
John Nagle writes: > I have a system which does error logging to its database: > > db = MySQLdb.connect(...) # get database connection > ... > errorlog(db, "Message") > > The problem is that I want errorlog to commit its message to > the table used for error logging, but don't

Re: Fibonacci: returning a selection of the series

2010-09-02 Thread Baba
On Aug 29, 7:18 pm, Alain Ketterlin wrote: > In general, if you have a program that produces something just to > remove/ignore it five lines later, you have a problem. In your case: > > 1) are you sure you need to append to list(*) at every iteration? When > do you *really* need to? And... > > 2)

Re: killing all subprocess childrens

2010-09-02 Thread Chris Rebert
On Thu, Sep 2, 2010 at 12:58 PM, Aahz wrote: > In article , > Astan Chee   wrote: >>Chris Rebert wrote: >>> >>> import os >>> import psutil # http://code.google.com/p/psutil/ >>> >>> # your piece of code goes here >>> >>> myself = os.getpid() >>> for proc in psutil.process_iter(): >> >>Is there a

Re: Speed-up for loops

2010-09-02 Thread Terry Reedy
On 9/2/2010 8:55 AM, Tim Wintle wrote: On Thu, 2010-09-02 at 12:02 +0200, Michael Kreim wrote: Hi, I was comparing the speed of a simple loop program between Matlab and Python. Unfortunately my Python Code was much slower and I do not understand why. The main reason is that, under the hood

Re: Sum of product-please help

2010-09-02 Thread MRAB
On 02/09/2010 23:01, Nally Kaunda-Bukenya wrote: Dear all, kindly help me with this code; This script is supposed to calculate Rvi for each row by first summing the product of #fields (Ai*Rv) and dividing by another field (Tot) such that Rvi=sum(Ai*Rv)/Tot. First it's acting like I need another p

Re: Selecting k smallest or largest elements from a large list in python; (benchmarking)

2010-09-02 Thread Terry Reedy
On 9/1/2010 9:08 PM, Dmitry Chichkov wrote: Given: a large list (10,000,000) of floating point numbers; Task: fastest python code that finds k (small, e.g. 10) smallest items, preferably with item indexes; Limitations: in python, using only standard libraries (numpy& scipy is Ok); I've tried se

Re: bisection method: Simulating a retirement fund

2010-09-02 Thread MRAB
On 02/09/2010 21:37, Baba wrote: level: beginner exercise source: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/assignments/pset4.pdf Problem 4 Can my code be optimised? I think my approach is correct but

Sum of product-please help

2010-09-02 Thread Nally Kaunda-Bukenya
Dear all, kindly help me with this code; This script  is supposed to calculate Rvi for each row by first summing the product of #fields (Ai*Rv) and dividing by another field (Tot) such that  Rvi=sum(Ai*Rv)/Tot. First it's acting like I need another parenthesis and it doesn't seem to work at all

Re: Performance: sets vs dicts.

2010-09-02 Thread Terry Reedy
On 9/1/2010 8:11 PM, John Bokma wrote: Terry Reedy writes: On 9/1/2010 5:40 PM, John Bokma wrote: [..] Yes, I switched, because 'constant time' is a comprehensible claim that can be refuted and because that is how some will interpret O(1) (see below for proof;-). You make it now sound as

Re: PyPy and RPython

2010-09-02 Thread John Nagle
On 9/2/2010 1:29 AM, sarvi wrote: When I think about it these restrictions below seem a very reasonable tradeoff for performance. Yes. And I can use this for just the modules/sections that are performance critical. Not quite. Neither Shed Skin nor RPython let you call from restricted

Obscure MySQLdb question - duplicating a database handle

2010-09-02 Thread John Nagle
I have a system which does error logging to its database: db = MySQLdb.connect(...) # get database connection ... errorlog(db, "Message") The problem is that I want errorlog to commit its message to the table used for error logging, but don't want to commit whatever the

Re: Performance: sets vs dicts.

2010-09-02 Thread Terry Reedy
On 9/1/2010 10:57 PM, ru...@yahoo.com wrote: So while you may "think" most people rarely read the docs for basic language features and objects (I presume you don't mean to restrict your statement to only sets), I and most people I know *do* read them. And when read them I expect them, as any go

bisection method: Simulating a retirement fund

2010-09-02 Thread Baba
level: beginner exercise source: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/assignments/pset4.pdf Problem 4 Can my code be optimised? I think my approach is correct but i am hesitant about the initial max

Re: Speed-up for loops

2010-09-02 Thread Carl Banks
On Sep 2, 5:55 am, Tim Wintle wrote: > On Thu, 2010-09-02 at 12:02 +0200, Michael Kreim wrote: > > Hi, > > > I was comparing the speed of a simple loop program between Matlab and > > Python. > > Unfortunately my Python Code was much slower and I do not understand why. > > The main reason is that,

Re: killing all subprocess childrens

2010-09-02 Thread Aahz
In article , Astan Chee wrote: >Chris Rebert wrote: >> >> import os >> import psutil # http://code.google.com/p/psutil/ >> >> # your piece of code goes here >> >> myself = os.getpid() >> for proc in psutil.process_iter(): > >Is there a way to do this without psutil or installing any external

Re: Help needed with Windows Service in Python

2010-09-02 Thread Edward Kozlowski
On Sep 2, 2:38 pm, Ian wrote: >   On 02/09/2010 20:06, Edward Kozlowski wrote: > > > > > On Sep 2, 10:22 am, Ian Hobson  wrote: > >> Hi All, > > >> I am attempting to create a Windows Service in Python. > > >> I have the framework (from Mark Hammond and Andy Robinason's book) > >> running - see be

Re: Help needed with Windows Service in Python

2010-09-02 Thread Ian
On 02/09/2010 20:06, Edward Kozlowski wrote: On Sep 2, 10:22 am, Ian Hobson wrote: Hi All, I am attempting to create a Windows Service in Python. I have the framework (from Mark Hammond and Andy Robinason's book) running - see below. It starts fine - but it will not stop. :( net stop "Pytho

Re: Windows vs. file.read

2010-09-02 Thread Thomas Jollans
On Thursday 02 September 2010, it occurred to ipatrol6...@yahoo.com to exclaim: > Correct in that regard. In Python 3.x, strings are by default considered > UTF-8. Wheras ASCII isn't a problem because it's fixed-width, UTF-8 will > give you a different character depending on the last byte value. T

RE: Speed-up for loops

2010-09-02 Thread Peter Otten
Philip Bloom wrote: > Uh. > Try: > Imax=10 > a=0 > i=0 > While(i a= a+10 > i=i+1 > print a > I suspect you will find it is way faster than using range or xrange for > large numbers and map far more closely in the final result to what you > are doing on matlab's side. At

Re: Help needed with Windows Service in Python

2010-09-02 Thread Edward Kozlowski
On Sep 2, 10:22 am, Ian Hobson wrote: > Hi All, > > I am attempting to create a Windows Service in Python. > > I have the framework (from Mark Hammond and Andy Robinason's book) > running - see below. It starts fine - but it will not stop. :( > > net stop "Python Service" > > and using the service

Re: MySQL Problem

2010-09-02 Thread Ian
On 02/09/2010 19:34, Victor Subervi wrote: for some reason running the command through python *omits* this one data!! The only difference is that a flag in spreadsheets (Temp) is set to 1. Why on earth doesn't it work in python?? Some ideas to follow up. (These are only guesses). 1) One of t

Re: Reversing a List

2010-09-02 Thread Victor Subervi
On Wed, Sep 1, 2010 at 9:26 AM, Shashwat Anand wrote: > > > On Wed, Sep 1, 2010 at 6:45 PM, Matt Saxton wrote: > >> On Wed, 1 Sep 2010 09:00:03 -0400 >> Victor Subervi wrote: >> >> > Hi; >> > I have this code: >> > >> > cursor.execute('describe products;') >> > cols = [item[0] for item in cu

Re: Help needed with Windows Service in Python

2010-09-02 Thread Ian
On 02/09/2010 18:03, David wrote: Il Thu, 02 Sep 2010 16:22:04 +0100, Ian Hobson ha scritto: self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) You may try to give a WaitHint parameter to ReportServiceStatus call, otherwise the Service Manager will expect the service is stopped istan

MySQL Problem

2010-09-02 Thread Victor Subervi
Hi; I have this code: print 'select * from spreadsheets s join products p on p.Item=s.Item join productsCategories pc on p.ID=pc.ProductsID join categories c on pc.CategoryID=c.ID where s.Client="%s" order by c.Category, c.Parent' % (client,) cursor.execute('select * from spreadsheets s jo

Re: Windows vs. file.read

2010-09-02 Thread ipatrol6...@yahoo.com
Correct in that regard. In Python 3.x, strings are by default considered UTF-8. Wheras ASCII isn't a problem because it's fixed-width, UTF-8 will give you a different character depending on the last byte value. Therefore handling any kind of data that is not UTF-8 will need you to open it with '

Re: Financial time series data

2010-09-02 Thread Hidura
But what kind of data you want to download?, because the financial time it's basicly html code and you can work very well with a parser 2010/9/2, Virgil Stokes : > Has anyone written code or worked with Python software for downloading > financial time series data (e.g. from Yahoo financial)? If

Re: Help needed with Windows Service in Python

2010-09-02 Thread ipatrol6...@yahoo.com
Well for one, if you're writing with pywin32, you certainly don't need the shbang line. #! /usr/bin/env is purely a POSIX thing. -- http://mail.python.org/mailman/listinfo/python-list

RE: Speed-up for loops

2010-09-02 Thread Philip Bloom
Uh. Try: Imax=10 a=0 i=0 While(imailto:python-list-bounces+pbloom=crystald@python.org] On Behalf Of Nobody Sent: Thursday, September 02, 2010 9:05 AM To: python-list@python.org Subject: Re: Speed-up for loops On Thu, 02 Sep 2010 12:02:40 +0200, Michael Kreim wrote: > I was comparin

Financial time series data

2010-09-02 Thread Virgil Stokes
Has anyone written code or worked with Python software for downloading financial time series data (e.g. from Yahoo financial)? If yes, would you please contact me. --Thanks, V. Stokes -- http://mail.python.org/mailman/listinfo/python-list

Re: Customizing cgitb

2010-09-02 Thread D'Arcy J.M. Cain
On Thu, 02 Sep 2010 19:02:35 +0200 Peter Otten <__pete...@web.de> wrote: > You could try to monkey-patch pydoc: I suppose so. Not a comfortable solution of course. It's bad enough when you get too familiar with the internals of a module but even worse when you need to get familiar with the inter

Re: Speed-up for loops

2010-09-02 Thread Tim Wintle
On Thu, 2010-09-02 at 16:13 +0200, Roland Koebler wrote: > Hi, > > > Are there any ways to speed up the for/xrange loop? > You can use psyco. Assuming you've got a 32-bit machine. -- http://mail.python.org/mailman/listinfo/python-list

Re: Customizing cgitb

2010-09-02 Thread Peter Otten
D'Arcy J.M. Cain wrote: > I have a small problem with the cgitb module. I know that I can > basically write my own version but it seems kind of silly to rewrite > something that does 99% what I want. Here is an excerpt from the > output of an exception. > > 1520 (current_job['j

Re: Help needed with Windows Service in Python

2010-09-02 Thread David
Il Thu, 02 Sep 2010 16:22:04 +0100, Ian Hobson ha scritto: > self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) You may try to give a WaitHint parameter to ReportServiceStatus call, otherwise the Service Manager will expect the service is stopped istantly. self.ReportServiceStatus(win32

Re: Windows vs. file.read

2010-09-02 Thread MRAB
On 02/09/2010 08:49, Lawrence D'Oliveiro wrote: In message, MRAB wrote: You should open the files in binary mode, not text mode, ie file(path, "rb"). Text mode is the default. Not a problem on *nix because the line ending is newline. We used to pride ourselves on not having to worry about tex

Re: Speed-up for loops

2010-09-02 Thread Nobody
On Thu, 02 Sep 2010 12:02:40 +0200, Michael Kreim wrote: > I was comparing the speed of a simple loop program between Matlab and > Python. > imax = 10 > a = 0 > for i in xrange(imax): > a = a + 10 > print a > Are there any ways to speed up the for/xrange loop? Sure; the above can

Customizing cgitb

2010-09-02 Thread D'Arcy J.M. Cain
I have a small problem with the cgitb module. I know that I can basically write my own version but it seems kind of silly to rewrite something that does 99% what I want. Here is an excerpt from the output of an exception. 1520 (current_job['job_id'], job['_SELECT_'])) 1521 15

Re: python path separator

2010-09-02 Thread Nobody
On Wed, 01 Sep 2010 23:57:21 -0700, swapnil wrote: > I could not find any documentation for variables os.path.sep and > os.path.altsep. Although the first is pretty straightforward can > anyone explain the purpose of the second variable? Is it even useful? The purpose is so that you can do e.g.:

Re: killing all subprocess childrens

2010-09-02 Thread Nobody
On Thu, 02 Sep 2010 13:12:07 +1000, Astan Chee wrote: > I have a piece of code that looks like this: > > import subprocess > retcode = subprocess.call(["java","test","string"]) > print "Exited with retcode " + str(retcode) > > What I'm trying to do (and wondering if its possible) is to make sure

Re: first non-null element in a list, otherwise None

2010-09-02 Thread Gerard Flanagan
wheres pythonmonks wrote: This should be trivial: I am looking to extract the first non-None element in a list, and "None" otherwise. Here's one implementation: x = reduce(lambda x,y: x or y, [None,None,1,None,2,None], None) print x 1 I thought maybe a generator expression would be better,

Help needed with Windows Service in Python

2010-09-02 Thread Ian Hobson
Hi All, I am attempting to create a Windows Service in Python. I have the framework (from Mark Hammond and Andy Robinason's book) running - see below. It starts fine - but it will not stop. :( net stop "Python Service" and using the services GUI both leave the services showing it as "stoppin

Re: first non-null element in a list, otherwise None

2010-09-02 Thread Arnaud Delobelle
On Sep 2, 2:48 pm, wheres pythonmonks wrote: > This should be trivial: > > I am looking to extract the first non-None element in a list, and > "None" otherwise.  Here's one implementation: > > >>> x = reduce(lambda x,y: x or y, [None,None,1,None,2,None], None) > >>> print x > > 1 > > I thought may

Re: argparse list

2010-09-02 Thread Michele Simionato
On Sep 2, 1:45 pm, Neal Becker wrote: > I'm interested in using argparse to parse a string formatted as: > > my_prog --option1=1,10,37 > > That is, a list of comma delimited values.  I guess nargs almost does it, > but expects options to be space-delimited. > > What would be the easiest approach?

Re: Speed-up for loops

2010-09-02 Thread Roland Koebler
Hi, > Are there any ways to speed up the for/xrange loop? You can use psyco. The following example should be about 4-times as fast as your example: import psyco psyco.full() def f(): imax = 10 a = 0 for i in xrange(imax): a += 10 print a f() regards, Ro

Re: first non-null element in a list, otherwise None

2010-09-02 Thread wheres pythonmonks
Peter wrote: >> But this can be expensive memory wise.  Is there a way to concatenate >> generator expressions? > > itertools.chain() > Aha! import itertools >>> x = itertools.chain( (x for x in [None,None] if x is not None), [ None ] >>> ).next() >>> print x None >>> x = itertools.chain( (x fo

Re: Speed-up for loops

2010-09-02 Thread Hrvoje Niksic
Michael Kreim writes: > Are there any ways to speed up the for/xrange loop? > Or do I have to live with the fact that Matlab beats Python in this > example? To a point, yes. However, there are things you can do to make your Python code go faster. One has been pointed out by Peter. Another is

Re: first non-null element in a list, otherwise None

2010-09-02 Thread Peter Otten
wheres pythonmonks wrote: > I am looking to extract the first non-None element in a list, and > "None" otherwise. Here's one implementation: > x = reduce(lambda x,y: x or y, [None,None,1,None,2,None], None) print x > 1 > > I thought maybe a generator expression would be better, to pre

first non-null element in a list, otherwise None

2010-09-02 Thread wheres pythonmonks
This should be trivial: I am looking to extract the first non-None element in a list, and "None" otherwise. Here's one implementation: >>> x = reduce(lambda x,y: x or y, [None,None,1,None,2,None], None) >>> print x 1 I thought maybe a generator expression would be better, to prevent iterating

Re: Speed-up for loops

2010-09-02 Thread Stefan Behnel
Tim Wintle, 02.09.2010 14:55: If you really need to optimise it then you can convert that module to cython by adding a cdef, and then compile it: cdef int i for i in xrange(imax): a = a + 10 print a or you can write it in C it'll run a lot faster. Just to get the context right here: a C

profiling qt programs

2010-09-02 Thread Duim
I'm trying to get a qt program a little faster by looking at the most expensive functions. To find out which functions are most important I wanted to profile the application using cProfile module. Unfortunately this runs through the complete code in 1 go without waiting until all threads (or in w

Re: Speed-up for loops

2010-09-02 Thread Tim Wintle
On Thu, 2010-09-02 at 12:02 +0200, Michael Kreim wrote: > Hi, > > I was comparing the speed of a simple loop program between Matlab and > Python. > Unfortunately my Python Code was much slower and I do not understand why. The main reason is that, under the hood, cpython does something like this

Re: parsing string into dict

2010-09-02 Thread Aleksey
On Sep 2, 12:46 am, Tim Arnold wrote: > Hi, > I have a set of strings that are *basically* comma separated, but with > the exception that if a comma occur insides curly braces it is not a > delimiter.  Here's an example: > > [code=one, caption={My Analysis for \textbf{t}, Version 1}, continued] >

Re: parsing string into dict

2010-09-02 Thread Aleksey
On Sep 2, 12:46 am, Tim Arnold wrote: > Hi, > I have a set of strings that are *basically* comma separated, but with > the exception that if a comma occur insides curly braces it is not a > delimiter.  Here's an example: > > [code=one, caption={My Analysis for \textbf{t}, Version 1}, continued] >

Re: argparse list

2010-09-02 Thread Peter Otten
Neal Becker wrote: > Peter Otten wrote: > > import argparse > def csv(value): >> ... return map(int, value.split(",")) >> ... > p = argparse.ArgumentParser() > p.add_argument("--option1", type=csv) and None > p.parse_args(["--option1=1,10,37"]) > > Thanks! But, why the '

Safely decoding user input

2010-09-02 Thread Tom Miller
Hello everyone, Before I pose my question, I should mention that I'm still pretty unfamiliar with proper terminology for string encoding, so I might get some of it wrong. Please bear with me. I'm writing a program that accepts arguments from the command line. Some of my users are using Windows wi

Re: argparse list

2010-09-02 Thread Neal Becker
Peter Otten wrote: import argparse def csv(value): > ... return map(int, value.split(",")) > ... p = argparse.ArgumentParser() p.add_argument("--option1", type=csv) and None p.parse_args(["--option1=1,10,37"]) Thanks! But, why the 'and None'? -- http://mail.python.

Re: argparse list

2010-09-02 Thread Peter Otten
Neal Becker wrote: > I'm interested in using argparse to parse a string formatted as: > > my_prog --option1=1,10,37 > > That is, a list of comma delimited values. I guess nargs almost does it, > but expects options to be space-delimited. > > What would be the easiest approach? >>> import argp

argparse list

2010-09-02 Thread Neal Becker
I'm interested in using argparse to parse a string formatted as: my_prog --option1=1,10,37 That is, a list of comma delimited values. I guess nargs almost does it, but expects options to be space-delimited. What would be the easiest approach? -- http://mail.python.org/mailman/listinfo/python

Re: Speed-up for loops

2010-09-02 Thread Peter Otten
Michael Kreim wrote: > Peter Otten wrote: >> Move it into a function; this turns a and i into local variables. >> >> def f(): >> imax = 10 >> a = 0 >> for i in xrange(imax): >> a = a + 10 >> print a >> f() > > Wow. It is still slower than Matlab, but your suggesti

Re: Speed-up for loops

2010-09-02 Thread Michael Kreim
Peter Otten wrote: Move it into a function; this turns a and i into local variables. def f(): imax = 10 a = 0 for i in xrange(imax): a = a + 10 print a f() Wow. It is still slower than Matlab, but your suggestion speeds up the code by ca 50%. But I do not under

Re: dirty problem 3 lines

2010-09-02 Thread bussiere bussiere
It seems to work perfectly thanks a lot Bussiere Google Fan boy On Thu, Sep 2, 2010 at 7:32 AM, alex23 wrote: > bussiere bussiere wrote: >> it's just as it seems : >> i want to know how does ti works to get back an object from a string in >> python : >> pickle.loads("""b'\x80\x03]q\x00(K\x00K

Re: Speed-up for loops

2010-09-02 Thread Peter Otten
Michael Kreim wrote: > I was comparing the speed of a simple loop program between Matlab and > Python. > > My Codes: > $ cat addition.py > imax = 10 > a = 0 > for i in xrange(imax): > a = a + 10 > print a > Are there any ways to speed up the for/xrange loop? Move it into a function

I GOT $5000 FROM PAYPAL BY SIMPLE HACK.

2010-09-02 Thread paypal cash
I GOT $5000 FROM PAYPAL BY SIMPLE HACK At http://happyandeasy.co.cc Due to high security risks, i have hidden the PayPal Form link in an image. in that website On RIGHT SIDE Below search box , click on image and enter your PAYPAL id And Your name. -- http://mail.python.org/mailman/listinfo/pyth

Re: python path separator

2010-09-02 Thread swapnil
On Sep 2, 12:25 pm, Vlastimil Brom wrote: > 2010/9/2 swapnil :> I could not find any documentation > for variables os.path.sep and > > os.path.altsep. Although the first is pretty straightforward can > > anyone explain the purpose of the second variable? Is it even useful? > > According to issueh

Speed-up for loops

2010-09-02 Thread Michael Kreim
Hi, I was comparing the speed of a simple loop program between Matlab and Python. My Codes: $ cat addition.py imax = 10 a = 0 for i in xrange(imax): a = a + 10 print a $ cat addition.m imax = 1e9; a = 0; for i=0:imax-1 a = a + 10; end disp(a); exit; The results look like this

comp.lang.python

2010-09-02 Thread roshini begum
www.127760.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Selecting k smallest or largest elements from a large list in python; (benchmarking)

2010-09-02 Thread Dmitry Chichkov
By the way, improving n-ARG-smallest (that returns indexes as well as values) is actually more desirable than just regular n-smallest: == Result == 1.38639092445 nargsmallest 3.1569879055 nargsmallest_numpy_argsort 1.29344892502 nargsmallest_numpy_argmin Note that numpy array constructor eats aro

Re: Selecting k smallest or largest elements from a large list in python; (benchmarking)

2010-09-02 Thread Dmitry Chichkov
Uh. I'm sorry about the confusion. Last three items are just O(N) baselines. Python min(), Numpy argmin(), Numpy asarray(). I'll update the code. Thanks! > A lot of the following doesn't run or returns incorrect results. > To give but one example: > > > def nargsmallest_numpy_argmin(iter, k): > >

Re: PyPy and RPython

2010-09-02 Thread sarvi
When I think about it these restrictions below seem a very reasonable tradeoff for performance. And I can use this for just the modules/sections that are performance critical. Essentially, the PyPy interpreter can have a restricted mode that enforces these restriction. This will help write such RP

Re: Selecting k smallest or largest elements from a large list in python; (benchmarking)

2010-09-02 Thread Peter Otten
Arnaud Delobelle wrote: > I get: > > 1.46s for _heapq.nsmallest > 0.85s for nsmallest_slott_bisect2 (version I posted) > > I am a bit surprised that mine is so slow compared with yours. I'll > do more tests later! Strange. I see a significant difference only for python3 (on 64bit Linux) $ pyt

Re: Queue cleanup

2010-09-02 Thread Paul Rubin
Dennis Lee Bieber writes: >> GC's for large systems ... copy the live objects to a new contiguous heap > That sounds suspiciously like the original Macintosh OS, with its > "handles"... IE, double-indirection. Nah, a double indirection on every access would be a terrible performance hit.

Re: fairly urgent request: paid python (or other) work required

2010-09-02 Thread Daniel Fetchinson
On 9/1/10, lkcl wrote: > i apologise for having to contact so many people but this is fairly > urgent, and i'm running out of time and options. i'm a free software > programmer, and i need some paid work - preferably python - fairly > urgently, so that i can pay for food and keep paying rent, an

Re: Is there a Python equivalent to Perl's File::Listing::parse_dir

2010-09-02 Thread Stefan Schwarzer
Hi John, On 2010-08-11 20:24, John Nagle wrote: >Perl has a function which will take a remote directory page, in > the form that most web sites return for a file directory, and > parse it into a useful form: > > http://www.xav.com/perl/site/lib/File/Listing.html > > This is especially

Re: Is python is the safest language ...

2010-09-02 Thread Chris Rebert
On Thu, Sep 2, 2010 at 12:29 AM, Anand Sadasivam wrote: > Hi All, > > Is python is the safest language is my question. I feel its good language, > but however java has good occupancy. About four years back I did few python > programs and worked with some of add-on product over ZOPE and Plone. The

Re: Windows vs. file.read

2010-09-02 Thread Lawrence D'Oliveiro
In message , MRAB wrote: > You should open the files in binary mode, not text mode, ie file(path, > "rb"). Text mode is the default. Not a problem on *nix because the line > ending is newline. We used to pride ourselves on not having to worry about text versus binary I/O modes on *nix, but I’m

Re: Selecting k smallest or largest elements from a large list in python; (benchmarking)

2010-09-02 Thread Arnaud Delobelle
On Sep 2, 7:59 am, Peter Otten <__pete...@web.de> wrote: > Dmitry Chichkov wrote: > > Given: a large list (10,000,000) of floating point numbers; > > Task: fastest python code that finds k (small, e.g. 10) smallest > > items, preferably with item indexes; > > Limitations: in python, using only stan

Re: Python-list Digest, Vol 84, Issue 8

2010-09-02 Thread Nally Kaunda-Bukenya
Dear Peter, that did wonders!! thanks so much for the code fix; I will check back with you later for the meaning of some functions you used. Many thanks to all those good people who gave me pointers: Rami, Mathew, Bob,   Best wishes for now:) From: "python-list

Is python is the safest language ...

2010-09-02 Thread Anand Sadasivam
Hi All, Is python is the safest language is my question. I feel its good language, but however java has good occupancy. About four years back I did few python programs and worked with some of add-on product over ZOPE and Plone. The suggestion to me is mostly welcome. Regards, -- Anand.S anand.s

Re: python path separator

2010-09-02 Thread Vlastimil Brom
2010/9/2 swapnil : > I could not find any documentation for variables os.path.sep and > os.path.altsep. Although the first is pretty straightforward can > anyone explain the purpose of the second variable? Is it even useful? > According to issue http://bugs.python.org/issue709428, os.path.altsep >

Re: Selecting k smallest or largest elements from a large list in python; (benchmarking)

2010-09-02 Thread Peter Otten
Dmitry Chichkov wrote: > Code: A lot of the following doesn't run or returns incorrect results. To give but one example: > def nargsmallest_numpy_argmin(iter, k): > distances = N.asarray(iter) > mins = [] Could you please provide an up-to-date version? Peter PS: for an easy way to en

Re: Selecting k smallest or largest elements from a large list in python; (benchmarking)

2010-09-02 Thread Peter Otten
Dmitry Chichkov wrote: > Given: a large list (10,000,000) of floating point numbers; > Task: fastest python code that finds k (small, e.g. 10) smallest > items, preferably with item indexes; > Limitations: in python, using only standard libraries (numpy & scipy > is Ok); > > I've tried several me

python path separator

2010-09-02 Thread swapnil
I could not find any documentation for variables os.path.sep and os.path.altsep. Although the first is pretty straightforward can anyone explain the purpose of the second variable? Is it even useful? According to issue http://bugs.python.org/issue709428, os.path.altsep was 'None' till a long time a