Re: modifying a time.struct_time

2011-12-23 Thread Chris Angelico
On Sat, Dec 24, 2011 at 5:04 PM, Jason Friedman wrote: > Not particularly elegant, but I believe accurate and relying only on > the stated struct_time contract: Funny! But a binary search would be better, I think. t = time.time() time1 = time.localtime(t) print("Local time is {}.".format(time1)

Re: modifying a time.struct_time

2011-12-23 Thread Jason Friedman
On Fri, Dec 16, 2011 at 10:44 AM, Chris Angelico wrote: > On Fri, Dec 16, 2011 at 8:45 PM, Ulrich Eckhardt > wrote: >> I'm trying to create a struct_time that is e.g. one year ahead or a month >> back in order to test some parsing/formatting code with different dates. > > Do you need it to be one

Re: merging argparse parsers

2011-12-23 Thread Jason Friedman
> I would like to have something like > > merged_parser = LoggingParser() + OtherParser() > > Which should create an argument parser with all the options composed. > I have used parent parsers. http://docs.python.org/py3k/library/argparse.html#parents I think in your case merged_parser would bec

Re: Idiom for shelling out to $EDITOR/$PAGER?

2011-12-23 Thread Owen Jacobson
On 2011-12-23 06:02:18 +, Cameron Simpson said: MacOSX has "open", though it won't be running a blocking editor, alas. But it can be. From the man page: -t Causes the file to be opened with the default text editor, as deter- mined via LaunchServices and -W Causes open

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-23 Thread Devin Jeanpierre
> To fake early binding when the language provides late binding, you still > use a sentinel value, but the initialization code creating the default > value is outside the body of the function, usually in a global variable: > >_DEFAULT_Y = [] # Private constant, don't touch. > >def func(x,

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-23 Thread Chris Angelico
On Sat, Dec 24, 2011 at 9:32 AM, Steven D'Aprano wrote: > Yes. But having to manage it *by hand* is still unclean: Well, my point was that Python's current behaviour _is_ that. > * you still have to assign the default value to the function assignment > outside the function, which is inelegant;

Re: Get named module's file location

2011-12-23 Thread Steven D'Aprano
On Fri, 23 Dec 2011 15:00:17 -0500, Roy Smith wrote: >> Can I in some way assign imp.find_module(module)[1] to a variable and >> reuse it? Is this a job for lambda? > > I think what you want to do is rewrite the list comprehension as a > regular loop. > > my_list = [] > for module in modules: >

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-23 Thread Steven D'Aprano
On Sat, 24 Dec 2011 02:55:41 +1100, Chris Angelico wrote: > On Sat, Dec 24, 2011 at 2:49 AM, Steven D'Aprano > wrote: >> To fake early binding when the language provides late binding, you >> still use a sentinel value, but the initialization code creating the >> default value is outside the body

Re: Get named module's file location

2011-12-23 Thread Chris Angelico
I'm guessing you meant for this to be on-list, and am hoping you don't mind that I'm replying on-list. On Sat, Dec 24, 2011 at 8:16 AM, Gnarlodious wrote: > Chris Angelico wrote: >> [(m, os.path.getmtime(m)) for m in (imp.find_module(module)[1] for >> module in modules)] >> >> Yeah, a little hard

Re: Idiom for shelling out to $EDITOR/$PAGER?

2011-12-23 Thread Devin Jeanpierre
> Windows may hate you for this with its locking behaviour for open files, > but it will work for UNIX. Windows won't let you open the file while NamedTemporaryFile has a hold on it, yeah. Your point is legitimate anyway. Even so, there's still the race conditions for "what if the tempfile is mov

Re: Get named module's file location

2011-12-23 Thread Roy Smith
In article <4652751.858.1324669248908.JavaMail.geo-discussion-forums@prj1>, Gnarlodious wrote: > I am rolling my own, and learning Python at the same time. Hmmm. The imp module is kind of deep magic for a first introduction to the language. But, whatever. > One more question. Say I want to

Re: Cannot Remove Python Libs from XP

2011-12-23 Thread W. eWatson
On 12/22/2011 1:21 PM, Dennis Lee Bieber wrote: On Thu, 22 Dec 2011 09:53:04 -0800, "W. eWatson" wrote: I have three py libs and the python program itself, 2.52, installed on an 6 year old HP Laptop. I decided to remove them, and took removed Python with the Control Panel ?Add/Remove icon. Wo

Re: Get named module's file location

2011-12-23 Thread Chris Angelico
On Sat, Dec 24, 2011 at 6:40 AM, Gnarlodious wrote: > [(imp.find_module(module)[1], os.path.getmtime(imp.find_module(module)[1])) > for module in modules] > > Can I in some way assign imp.find_module(module)[1] to a variable and reuse > it? Is this a job for lambda? Well, you can use an additio

Re: Idiom for shelling out to $EDITOR/$PAGER?

2011-12-23 Thread Cameron Simpson
On 23Dec2011 02:21, Devin Jeanpierre wrote: | > Anyway, look it up; it has an autodelete mode etc. | | The autodelete isn't useful in this context. The file needs to be | closed and then reopened again; with the autodelete option, the | closing would delete the file, preventing it from being open

Re: Get named module's file location

2011-12-23 Thread Gnarlodious
I am rolling my own, and learning Python at the same time. One more question. Say I want to assemble a list of tuples like this: modules = ['wsgiref', 'http'] import imp [(imp.find_module(module)[1], os.path.getmtime(imp.find_module(module)[1])) for module in modules] Can I in some way assign i

Re: what does 'a=b=c=[]' do

2011-12-23 Thread Michael Torrie
On 12/23/2011 03:31 AM, rusi wrote: > In Fortran, if the comma in the loop > DO 10 I = 1,10 > is misspelt as '.' it becomes the assignment > DO10I = 1.0 > > Do you consider it a bug or a feature? > Does Fortran consider it a bug or feature? Non sequitor. Nothing at all to do with the issue at ha

Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error

2011-12-23 Thread Νικόλαος Κούρας
On 23 Δεκ, 12:41, becky_lewis wrote: > Is there any possibility that you can tell us what the script actually > is or provide a code listing (use pastebin if it's big)? The script is about retrieving and storing the visitros hostnames to mysql database creating a log file. I dont know why this l

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-23 Thread Neil Cerutti
On 2011-12-23, Steven D'Aprano wrote: > On Fri, 23 Dec 2011 13:13:38 +, Neil Cerutti wrote: >> On 2011-12-23, Neil Cerutti wrote: >>> Is the misfeature that Python doesn't evaluate the default >>> argument expression every time you call the function? What >>> would be the harm if it did? >>

Re: Get named module's file location

2011-12-23 Thread Roy Smith
In article <4946660.379.1324659073535.JavaMail.geo-discussion-forums@prez5>, Gnarlodious wrote: > Roy Smith wrote: > > > import imp > > imp.find_module() > > Oh yeah that works. I am getting a list of modtimes using List Comprehension, > from a list of modules, which will be compared to an o

Re: Get named module's file location

2011-12-23 Thread Gnarlodious
Roy Smith wrote: > import imp > imp.find_module() Oh yeah that works. I am getting a list of modtimes using List Comprehension, from a list of modules, which will be compared to an older list to see if mod_wsgi needs to be restarted. Maybe thee is an easy way to get the modtimes, I'd be gratef

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-23 Thread Mel Wilson
Steven D'Aprano wrote: > On Fri, 23 Dec 2011 13:13:38 +, Neil Cerutti wrote: >> On 2011-12-23, Neil Cerutti wrote: >> ...you know, assuming it wouldn't break existing code. ;) > > It will. Python's default argument strategy has been in use for 20 years. > Some code will rely on it. I know min

Re: Get named module's file location

2011-12-23 Thread Roy Smith
In article <32472953.855.1324656114851.JavaMail.geo-discussion-forums@prix23>, Gnarlodious wrote: > Given a module's name, how do I get the file path without importing it? > Searched all over, can't find any such info. > > Is it possible to ask if a named module exists before attempting an im

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-23 Thread Roy Smith
In article <4ef4a30d$0$29973$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > The disadvantage of late binding is that since the expression is live, it > needs to be calculated each time, even if it turns out to be the same > result. But there's no guarantee that it will return th

Re: Get named module's file location

2011-12-23 Thread Yaşar Arabacı
>>> import imp >>> imp.find_module("os") (, '/usr/lib/python2.7/os.py', ('.py', 'U', 1)) >>> 2011/12/23 Gnarlodious > Given a module's name, how do I get the file path without importing it? > Searched all over, can't find any such info. > > Is it possible to ask if a named module exists before a

Get named module's file location

2011-12-23 Thread Gnarlodious
Given a module's name, how do I get the file path without importing it? Searched all over, can't find any such info. Is it possible to ask if a named module exists before attempting an import? Or are we forced to import first and catch any failure? -- Gnarlie -- http://mail.python.org/mailman/

Re: what does 'a=b=c=[]' do

2011-12-23 Thread rusi
On Dec 23, 8:33 pm, Steven D'Aprano wrote: > On Fri, 23 Dec 2011 06:57:02 -0800, rusi wrote: > > On Dec 23, 6:53 pm, Robert Kern wrote: > >> On 12/23/11 1:23 PM, rusi wrote: > [...] > >> > Of course it should be fixed.  The repeated recurrence of it as a > >> > standard gotcha as well as the pyth

Re: Need advice on the design of my application

2011-12-23 Thread Eelco
My first suggestion would be to keep the rendering in Python, if at all feasible, and do only the actual simulation/computation in C. Rasterizing a heightfield and rigid body plus some plash effects is nothing that couldnt be done in PyOpenGL, or even something higher- level like visvis or mayavi.

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-23 Thread Chris Angelico
On Sat, Dec 24, 2011 at 2:49 AM, Steven D'Aprano wrote: > To fake early binding when the language provides late binding, you still > use a sentinel value, but the initialization code creating the default > value is outside the body of the function, usually in a global variable: > >    _DEFAULT_Y =

Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-23 Thread Steven D'Aprano
On Fri, 23 Dec 2011 13:13:38 +, Neil Cerutti wrote: > On 2011-12-23, Neil Cerutti wrote: >> Is the misfeature that Python doesn't evaluate the default argument >> expression every time you call the function? What would be the harm if >> it did? > > ...you know, assuming it wouldn't break exi

Re: what does 'a=b=c=[]' do

2011-12-23 Thread Steven D'Aprano
On Fri, 23 Dec 2011 06:57:02 -0800, rusi wrote: > On Dec 23, 6:53 pm, Robert Kern wrote: >> On 12/23/11 1:23 PM, rusi wrote: [...] >> > Of course it should be fixed.  The repeated recurrence of it as a >> > standard gotcha as well as the python ideas list testifies to that. >> >> So you were lyin

Re: Grammar for classes

2011-12-23 Thread Joshua Landau
On 22 December 2011 23:39, Terry Reedy wrote: > On 12/20/2011 12:05 PM, Joshua Landau wrote: > >> Should I file a documentation bug report? >> > > Please do. It the addition means something, it needs to be explained in > the text. If it is wrong, it should go. I have filed one at issue13658

Re: what does 'a=b=c=[]' do

2011-12-23 Thread rusi
On Dec 23, 6:53 pm, Robert Kern wrote: > On 12/23/11 1:23 PM, rusi wrote: > > > > > > > > > > > On Dec 23, 6:10 pm, Robert Kern  wrote: > >> On 12/23/11 10:22 AM, rusi wrote: > >>> On Dec 23, 2:39 pm, Steven D'Aprano >>> +comp.lang.pyt...@pearwood.info>    wrote: > Some people might argue tha

Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error

2011-12-23 Thread becky_lewis
Is there any possibility that you can tell us what the script actually is or provide a code listing (use pastebin if it's big)? -- http://mail.python.org/mailman/listinfo/python-list

Re: what does 'a=b=c=[]' do

2011-12-23 Thread Robert Kern
On 12/23/11 1:23 PM, rusi wrote: On Dec 23, 6:10 pm, Robert Kern wrote: On 12/23/11 10:22 AM, rusi wrote: On Dec 23, 2:39 pm, Steven D'Apranowrote: Some people might argue that it is a mistake, a minor feature which allegedly causes more difficulties than benefits. I do not hold with th

Re: what does 'a=b=c=[]' do

2011-12-23 Thread rusi
On Dec 23, 6:10 pm, Robert Kern wrote: > On 12/23/11 10:22 AM, rusi wrote: > > > > > > > > > > > On Dec 23, 2:39 pm, Steven D'Aprano > +comp.lang.pyt...@pearwood.info>  wrote: > >> On Fri, 23 Dec 2011 00:38:07 -0800, rusi wrote: > >>> Likewise function arguments that default to mutable entities is

Re: what does 'a=b=c=[]' do

2011-12-23 Thread Neil Cerutti
On 2011-12-23, Chris Angelico wrote: > On Fri, Dec 23, 2011 at 7:49 PM, Ethan Furman wrote: >> That is the most ridiculous thing I have heard in a while. >> ?Mutable default arguments are *not* a bug in Python. >> >> Reminds me of a bug report a couple years back claiming >> multiple inheritence

Re: what does 'a=b=c=[]' do

2011-12-23 Thread Neil Cerutti
On 2011-12-23, Neil Cerutti wrote: > Is the misfeature that Python doesn't evaluate the default > argument expression every time you call the function? What > would be the harm if it did? ...you know, assuming it wouldn't break existing code. ;) -- Neil Cerutti -- http://mail.python.org/mailma

Re: what does 'a=b=c=[]' do

2011-12-23 Thread Robert Kern
On 12/23/11 10:22 AM, rusi wrote: On Dec 23, 2:39 pm, Steven D'Aprano wrote: On Fri, 23 Dec 2011 00:38:07 -0800, rusi wrote: Likewise function arguments that default to mutable entities is a known gotcha of python which is best treated as a bug in python. Nonsense. It is a feature, not a bug

Timeout when calling COM objects on Windows

2011-12-23 Thread Wong Wah Meng-R32813
Hello there, I am converting my VB ActiveX application written sometime back in year 2000 with python 1.5.2 to run in python 2.7.1. My application is using RMI architecture and I am using a pythonOleRmi.py parser to exchange data/objects between the python and the VB exe. I have no issue whe

Re: Idiom for shelling out to $EDITOR/$PAGER?

2011-12-23 Thread Tim Chase
On 12/23/11 06:06, Ben Finney wrote: Cameron Simpson writes: On 23Dec2011 17:12, Ben Finney wrote: | That doesn't address the concern Tim raised: did the user actually do | anything, did the file change? I'm not sure it matters. I know of numerous applications where it matters, spcifically o

Re: IPC with multiprocessing.connection

2011-12-23 Thread Andrew Berg
On 12/23/2011 5:50 AM, bobicanprogram wrote: You might want to check out the code samples at: http://www.icanprogram.com/06py/lesson1/lesson1.html Let's see, I asked about a method in the multiprocessing module, and you recommend code snippets that run on Python versions that don't even have th

Re: what does 'a=b=c=[]' do

2011-12-23 Thread rusi
On Dec 23, 2:39 pm, Steven D'Aprano wrote: > On Fri, 23 Dec 2011 00:38:07 -0800, rusi wrote: > > Likewise function arguments that default to mutable entities is a known > > gotcha of python which is best treated as a bug in python. > > Nonsense. It is a feature, not a bug. Tsk Tsk How can python

Re: Idiom for shelling out to $EDITOR/$PAGER?

2011-12-23 Thread Ben Finney
Cameron Simpson writes: > On 23Dec2011 17:12, Ben Finney wrote: > | That doesn't address the concern Tim raised: did the user actually do > | anything, did the file change? > > I'm not sure it matters. I know of numerous applications where it matters, spcifically ones which decide what to do wi

ANN: PyQt v4.9 Released (Python bindings for Qt)

2011-12-23 Thread Phil Thompson
PyQt v4.9 has been released and is available from http://www.riverbankcomputing.com/software/pyqt/. PyQt is a comprehensive set of bindings for the Qt application and UI framework from Nokia. It supports the same platforms as Qt (Windows, Linux and MacOS/X). PyQt supports Python v3 and Python v2

Re: IPC with multiprocessing.connection

2011-12-23 Thread bobicanprogram
On Dec 22, 3:27 pm, Andrew Berg wrote: > I'm trying to set up a system where my main program launches external > programs and then establishes connections to them via named pipes or > Unix domain sockets (depending on platform) with > multiprocessing.connection.Listener. The issue I'm having is wi

Re: what does 'a=b=c=[]' do

2011-12-23 Thread rusi
On Dec 23, 2:59 pm, Chris Angelico wrote: > On Fri, Dec 23, 2011 at 7:49 PM, Ethan Furman wrote: > > That is the most ridiculous thing I have heard in a while.  Mutable default > > arguments are *not* a bug in Python. > > > Reminds me of a bug report a couple years back claiming multiple inherite

Re: Idiom for shelling out to $EDITOR/$PAGER?

2011-12-23 Thread Steven D'Aprano
On Thu, 22 Dec 2011 22:16:30 -0600, Tim Chase wrote: > I presume the code for spawning $PAGER on some content would look pretty > similar. Have a look at pydoc in the standard library, which implements pager-like functionality. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: what does 'a=b=c=[]' do

2011-12-23 Thread Chris Angelico
On Fri, Dec 23, 2011 at 7:49 PM, Ethan Furman wrote: > That is the most ridiculous thing I have heard in a while.  Mutable default > arguments are *not* a bug in Python. > > Reminds me of a bug report a couple years back claiming multiple inheritence > was a bug and asking it to be removed. Both

Re: what does 'a=b=c=[]' do

2011-12-23 Thread Ethan Furman
rusi wrote: On Dec 23, 7:10 am, alex23 wrote: On Dec 22, 6:51 pm, Rolf Camps wrote: I'm afraid it's dangerous to encourage the use of '[]' as assignment to a parameter in a function definition. If you use the function several times 'default' always points to the same list. >> I appreciate

Re: Idiom for shelling out to $EDITOR/$PAGER?

2011-12-23 Thread Steven D'Aprano
On Fri, 23 Dec 2011 09:44:31 +, Steven D'Aprano wrote: > On Fri, 23 Dec 2011 09:28:52 +0100, Peter Otten wrote: > >>> -proper & efficient detection of file-change, to know whether the user >>> actually did anything >> >> Just read the whole thing back into memory and compare the string to >>

Re: Idiom for shelling out to $EDITOR/$PAGER?

2011-12-23 Thread Steven D'Aprano
On Fri, 23 Dec 2011 09:28:52 +0100, Peter Otten wrote: >> -proper & efficient detection of file-change, to know whether the user >> actually did anything > > Just read the whole thing back into memory and compare the string to the > original data. The file has to be quite long for the checksum >

Re: what does 'a=b=c=[]' do

2011-12-23 Thread Steven D'Aprano
On Fri, 23 Dec 2011 00:38:07 -0800, rusi wrote: > Likewise function arguments that default to mutable entities is a known > gotcha of python which is best treated as a bug in python. Nonsense. It is a feature, not a bug. Some people might argue that it is a mistake, a minor feature which allege

Re: what does 'a=b=c=[]' do

2011-12-23 Thread Ethan Furman
Ian Kelly wrote: On Thu, Dec 22, 2011 at 7:10 PM, alex23 wrote: On Dec 22, 6:51 pm, Rolf Camps wrote: I'm afraid it's dangerous to encourage the use of '[]' as assignment to a parameter in a function definition. If you use the function several times 'default' always points to the same list.

Re: IPC with multiprocessing.connection

2011-12-23 Thread Andrew Berg
On 12/23/2011 2:32 AM, Deepak Babu wrote: See if http://www.rsdcbabu.com/2011/02/multiprocessing-with-python.htmlhelps you. It doesn't. There is not even a mention of the connection submodule (plus it's Python 2, and I'm familiar enough with Python 2 to do a good job of porting to py3k). I don'

Re: what does 'a=b=c=[]' do

2011-12-23 Thread rusi
On Dec 23, 7:10 am, alex23 wrote: > On Dec 22, 6:51 pm, Rolf Camps wrote: > > > I'm afraid it's dangerous to encourage the use of '[]' as assignment to > > a parameter in a function definition. If you use the function several > > times 'default' always points to the same list. > > I appreciate th

Re: Idiom for shelling out to $EDITOR/$PAGER?

2011-12-23 Thread Peter Otten
Tim Chase wrote: > After a little searching, I've not been able to come up with what > I'd consider canonical examples of consider calling an external > editor/pager on a file and reading the results back in. (most of > my results are swamped by people asking about editors written in > Python, or