tracing openurl input and output?
How can I watch the messages being sent back and for on urllib shttp requests? If it were simple http I would just watch the socket traffic but of course that won't work for https. Is there a debug flag I can set that will do this? context: I am dealing with a web service bug and I want to tell the provider exactly what is going back and forth to his server, eliminating the maybe there's a bug in your library chat. import urllib params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) f = urllib.urlopen(https://example.com/cgi-bin/query;, params) Many TIA! -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
parsing times like 5 minutes ago?
I'm looking for something like Tcl's [clock scan] command which parses human-readable time strings such as: % clock scan 5 minutes ago 1246925569 % clock scan tomorrow 12:00 1246993200 % clock scan today + 1 fortnight 1248135628 Does any such package exist for Python? Many TIA! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
Re: preferring [] or () in list of error codes?
John Machin sjmac...@lexicon.net wrote: T=lambda x:x in(25401,25402,25408);import dis;dis.dis(L);dis.dis(T) I've learned a lot from this thread, but this is the niftiest bit I've picked up... thanks! -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
setting program name, like $0= in perl?
I'm sure this is a FAQ, but I certainly haven't been able to find an answer. Is it possible to set the program name as seen by the operating system or lower-level libraries? I'm connecting to a database, and the runtime helpfully sends some information to the server, such as username, pid, and program name. Unfortunately, all my python programs get the name '/usr/bin/python', and I would like to force that to be the names of the individual scripts. Many TIA! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
preferring [] or () in list of error codes?
Is there any reason to prefer one or the other of these statements? if e.message.code in [25401,25402,25408]: if e.message.code in (25401,25402,25408): I'm currently using [], but only coz I think it's prettier than (). context: these are database errors and e is database exception, so there's probably been zillions of instructions and io's handling that already. Many TIA! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
#! to two different pythons?
I've got a bunch of python programs on linux that start with: #!/usr/anim/menv/bin/pypix Now I'm moving some to the mac, where I'm changing that to: #!/Users/mh/py/bin/python What's the best way to handle this? I've got an install script that rewrites the first line, but if I could eliminate that step I would be quite happy, since it's the only thing the install step does. TIA!! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
Re: #! to two different pythons?
Benjamin Peterson benja...@python.org wrote: #!/usr/bin/env python But how can I handle this with two differently named pythons? #!/usr/anim/menv/bin/pypix #!/Users/mh/py/bin/python Thanks! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
Re: #! to two different pythons?
Cameron Simpson c...@zip.com.au wrote: - Keep the #!/usr/bin/env python and then: ln -s /usr/anim/menv/bin/pypix /usr/local/bin/python Ah, that's a good idea. The pypix is a company-wide maintained python, but ln -s python pypix on my local Mac laptop python install makes the env work quite nicely. The ~/bin and ~/bin-local is a great idea too... I've symlinked to my dropbox account for bonus convenience. thanks!!! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
Re: best way to parse a function-call-like string?
Paul McGuire pt...@austin.rr.com wrote: Pyparsing will easily carve up these function declarations, and will I didn't know about this module, it looks like what I was looking for... Thanks!!! -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
best way to parse a function-call-like string?
I have some strings that look like function calls, e.g. junkpkg.f1 junkpkg.f1() junkpkg.f1('aaa') junkpkg.f1('aaa','bbb') junkpkg.f1('aaa','bbb','ccc') junkpkg.f1('aaa','with,comma') and I need to split them into the function name and list of parms, e.g. junkpkg.f1, [] junkpkg.f1, [] junkpkg.f1, ['aaa'] junkpkg.f1, ['aaa','bbb'] junkpkg.f1, ['aaa','bbb','ccc'] junkpkg.f1, ['aaa','with,comma'] What's the best way to do this? I would be interested in either of two approaches: - a real way which comprehensively - a quick-and-dirty way which handles most cases, so that I can get my coding partner running quickly while I do the real way. will the csv module do the right thing for the parm list? Many TIA!! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
Re: best way to parse a function-call-like string?
Robert Kern robert.k...@gmail.com wrote: On 2009-02-26 15:29, m...@pixar.com wrote: Use the compiler module to generate an AST and walk it. That's the real way. For me, that would also be the quick way because I am familiar with the API, but it may take you a little bit of time to get used to it. ah, that's just what I was hoping for... in the meantime, here's my quick and dirty: import csv def fakeparse(s): print === argl=[] ix=s.find('(') if ix == -1: func=s argl=[] else: func=s[0:ix] argstr=s[ix+1:] argstr=argstr[:argstr.rfind(')')] print argstr for argl in csv.reader([argstr], quotechar='): pass print s print func print argl return func,argl print fakeparse(junkpkg.f1) print fakeparse(junkpkg.f1()) print fakeparse(junkpkg.f1('aaa')) print fakeparse(junkpkg.f1('aaa','bbb')) print fakeparse(junkpkg.f1('aaa','bbb','ccc')) print fakeparse(junkpkg.f1('aaa','xx,yy')) -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
Re: var or inout parm?
J. Clifford Dyer j...@sdf.lonestar.org wrote: Just google for call-by-object, and ignore the hell out of that thread. Now I've got to go read it! ;-) -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
Re: var or inout parm?
Chris Rebert [EMAIL PROTECTED] wrote: Not directly possible or encouraged. You can emulate it by sticking the value in a container object (e.g. list) though: Thanks, that's just what I needed. I'm using this to monkeypatch a test driver into some code that I can't touch, otherwise I would just have the function return a tuple with the replacement values. Cheers! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
var or inout parm?
How can I make a var parm, where the called function can modify the value of the parameter in the caller? def f(x): x = x + 1 n = 1 f(n) # n should now be 2 Many TIA!! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
who to thank for the new RST doc format?
I am really loving the output, and have started using RST for some of my own docs as well. It's wonderful and I know it was a lot of work on somebody's part to think it through and make the changes. If it was you, Many Thanks!!! -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
Re: etymology of list comprehension?
Martin v. Lowis [EMAIL PROTECTED] wrote: The definition in logic, in turn, matches my understanding of the English word to comprehend: If I know all attributes, marks, etc of an object, I understand it fully, i.e. I comprehend it. I think also that as was pointed out, comprehension meaning comprehensive also makes sense, e.g. a comprehensive definition of positive odd numbers: { x | x = 2k+1, for all integers k = 0 } as opposed to { 1, 3, 5, ... } Thanks everybody, I feel much better informed now! -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
best way to accelerate xmlrpc?
I've got some python xmlrpc servers and clients. What's the best way to accelerate them? xmlrpclib.py attempts to import these modules: import _xmlrpclib import sgmlop from xml.parsers import expat and falls back to defining the SlowParser class. So, which of these modules is the preferred one to build for python 2.5? for python 2.6? Many TIA! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
etymology of list comprehension?
I googled and wiki'ed, but couldn't find a concise clear answer as to how python list comprehensions got their name. Who picked the name? What was the direct inspiration, another language? What language was the first to have such a construct? I get that it's based on set notation. Thanks! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
Re: etymology of list comprehension?
Chris Rebert [EMAIL PROTECTED] wrote: the term comprehension for the concept was first used in the NPL programming language (Wikipedia again). Ah, thanks... and does comprehension have any special computer science meaning? -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
wrapping a method function call?
I am instantiating a class A (which I am importing from somebody else, so I can't modify it) into my class X. Is there a way I can intercept or wrape calls to methods in A? I.e., in the code below can I call x.a.p1() and get the output X.pre A.p1 X.post Many TIA! Mark class A: # in my real application, this is an imported class # that I cannot modify def p1(self): print 'A.p1' class X: def __init__(self): self.a=A() def pre(self): print 'X.pre' def post(self): print 'X.post' x=X() x.a.p1() -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
Re: wrapping a method function call?
Steven D'Aprano [EMAIL PROTECTED] wrote: Now you can monkey patch class A if you want. It's probably not a great idea to do this in production code, as it will effect class A everywhere. This is perfect for me. The code in question is basically a protocol translator... it receives requests over the network, makes some calls, and returns the result translated back to the original protocol, so there's a single instance of each A,B, etc. A.p1 = precall(pre)(postcall(post)(A.p1)) Is there a way to do this for all callable methods of A? e.g. for x in callable_methods(A): x = precall(pre)(postcall(post)(x)) Thanks! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
subdirectories for sys.path import?
I'm currently sharing a directory on sys.path with another group. We don't have the option to modify sys.path. In order to reduce conflicts between the two group's code, installation procedures, etc, I'd like to make a subdirectory for each group, and have each group manage their own subdirectory. /oursharedpath/lib/python/group1 /oursharedpath/lib/python/group2 Is there a way to import a module from one of these subdirectories? Any other more pythonic ways to approach the situation? Many TIA! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
Re: subdirectories for sys.path import?
[EMAIL PROTECTED] wrote: Is there a way to import a module from one of these subdirectories? Any other more pythonic ways to approach the situation? ah, the magic of __init__.py. Thanks all! -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
Re: SimpleXMLRPCServer -- turning off request log?
Vinay Sajip [EMAIL PROTECTED] wrote: Did you try setting logRequests to false? Perfect, that's just what I needed. Thanks Vinay!! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
SimpleXMLRPCServer -- turning off request log?
My SimpleXMLRPCServer program prints to stderr a line like this for each request: ohm..pixar.com - - [25/Sep/2008 17:57:50] POST /RPC2 HTTP/1.0 200 - Is there a way to turn this logging off? I have RTFM and can't seem to find a way to do so. Many TIA! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
[1,2,3] exactly same as [1,2,3,] ?
x=[1,2,3] and x=[1,2,3,] are exactly the same, right? I'm generating some python data, and it's less error prone to not treat the last element specially, but I want to be sure I'm generating an equivalent data structure. Many TIA! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
Re: [1,2,3] exactly same as [1,2,3,] ?
Paul McNett [EMAIL PROTECTED] wrote: When confronted with this type of question, I ask the interpreter: [1,2,3] == [1,2,3,] True Well I guess that's a pretty authoritative answer... thanks! -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
iterating over two arrays in parallel?
I want to interate over two arrays in parallel, something like this: a=[1,2,3] b=[4,5,6] for i,j in a,b: print i,j where i,j would be 1,4,2,5, 3,6 etc. Is this possible? Many TIA! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
Best idiom for looping over input?
What's the best Python idiom for this C construct? while ((x = next()) != END) { } Now I'm doing x = next() while x != END: x = next() There's not an iterator for this function, or I would just use for x in ... Many TIA! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
http server class that lets me open socket?
I'm writing a select-based server, and some of the client connections will want to send an xml-rpc request. Is there a class in the http hierarchy that will allow me to manage a socket, and allow me to instantiate the class like myhttpserver = SomeHTTPServer(mysocket) and then let me call something like myhttpserver.processOneRequest() Many TIA! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
best option for python lex/yacc?
I'm porting a C lex/yacc based project, and would like to redo it in python. What's the best option for a python lex/yacc-like? I've googled a few things, but wanted to see the current concensus. Many TIA! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
getting dir(x), but not as list of strings?
I want to iterate over members of a module, something like: for i in dir(x): if type(i) == types.FunctionType: ... but of course dir() returns a list of strings. If x is a module, how can I get the list of its members as their actual types? Many TIA! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
call tree tool?
I'm cleaning up some old code, and want to see what orphan functions might be sitting around. Is there a static call tree analyzer for python? Many TIA! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
best way to have enum-like identifiers?
I currently have a 2-dim hash, indexed by two strings: template['py']['funcpre'] template['py']['funcpost'] ... but I would prefer to have these indexed by constants of some kind, since this seems a bit more natural: template[py][funcpre] template[py][funcpost] ... Currently I'm just putting this at the top of the file: py=1 funcpre=2 funcpost=3 ... but I'm curious if there's a better way of doing this, some kind of enum-like thing or somesuch. Many TIA! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
Re: any chance regular expressions are cached?
John Machin [EMAIL PROTECTED] wrote: Yes they will be cached. great. But do yourself a favour and check out the string methods. Nifty... thanks all! -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
any chance regular expressions are cached?
I've got a bit of code in a function like this: s=re.sub(r'\n','\n'+spaces,s) s=re.sub(r'^',spaces,s) s=re.sub(r' *\n','\n',s) s=re.sub(r' *$','',s) s=re.sub(r'\n*$','',s) Is there any chance that these will be cached somewhere, and save me the trouble of having to declare some global re's if I don't want to have them recompiled on each function invocation? Many TIA! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
Re: nonblocking read of one xml element?
Stefan Behnel [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: I'm parsing a log file that's being written out in real time. This is part of an event loop, so I want to have some code that looks like this: when logfile is readable: read one entry node, including children but don't try to read past /entry, so that the read won't block. Do you have any control over the program that writes the log file? Maybe you could make it write the log to a pipe or socket instead, which you could then connect an XML parser to from the Python side (maybe from a thread to avoid blocking I/O). Unfortunately, no... it's the oracle database, which can write its auditing logs to external xml files. This is great because we can tail those files in real time and follow what is going on. Basically, they have one audit xml file per session, and they write the filename to a control file every time they create a new audit file. So, the logic is something like this: whenever the control file is readable: # a new audit file has been created read audit filename, open, read xml header up to first audit record, and set up readable callback whenever an audit logfile is readable: read the next auditlog # but don't block Or perhaps there's some nonblocking file I/O I can do? Thanks, Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
nonblocking read of one xml element?
So, I'm parsing a log file that's being written out in real time. logfile entrytimestamp123/timestampdetailsfoo/details /entry entrytimestamp456/timestampdetailsbar/details /entry --- no /logfile, coz the file hasn't yet been closed This is part of an event loop, so I want to have some code that looks like this: when logfile is readable: read one entry node, including children but don't try to read past /entry, so that the read won't block. Any clues greatly appreciated, Many TIA! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
compiling an extension for several versions of python
I don't have access to site-packages, but I would like to provide versions of my c-language package compiled against python 2.4 and 2.5. I own a library directory which is included in our site's sys.path. Currently this is where the 2.4 shared libary is installed. What's the most canonical way of doing this? This is on linux. Many TIA! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
Determine if windows drive letter is hard drive or optical from python?
Hi Folks- I'm trying to do a simple emulation of unix locate functionality in python for windows. Problem is I don't want to crawl/index optical drives. Do any of the windows people out there know how I can determine: 1. How many drives are on the system? (I could just iterate over the alphabet os.path.exists(%s:\\%letter) ... is there a windows way of doing it?) 2. More importantly for those drives that exist, how do I determine if it is actually a harddrive? thanks matt -- http://mail.python.org/mailman/listinfo/python-list
[ANN] Spike Asset Manager release 0.13
Spike Asset Manager (SAM) is an open-source cross-platform framework written in python for probing a system for components and reporting them. It includes a driver file that probes for components commonly found in a LAMPJ stack (Apache, MySQL, PHP, Tomcat, etc). Note that the L in LAMP could be Linux, Solaris, Windows or Mac. SAM can find multiple versions that are installed, query the rpm database and indicate whether components are running. Release 0.13 changes: - Migrate to ElementTree from minidom - Migrate to Cheetah from xsl - Preliminary MacOSX support thanks Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: [ANN] Spike Asset Manager release 0.13
The idea is to have a framework to do this in a semi-crossplatform manner. The framework could be updated to know about apt, portage repositories as well as talk to to the windows registry. Not everyone is running redhat ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: [ANN] Spike Asset Manager release 0.13
Fredrik- This is a known issue. The tool currently only looks in certain locations or hints rather then spidering the whole hard drive (which could take a bit of time). If you have installed in a non-standard location (or are using a platform or version of software that hasn't been tested against) the tool won't find the component. One way around this is manually enter more hints but this doesn't scale. I'm open to suggestions for handling this in a better way. matt ps-I assume you are running on windows. Where is python installed on your machine? -- http://mail.python.org/mailman/listinfo/python-list