Gajim 0.8
Gajim 0.8 is now available. Gajim is a Jabber client for GTK+/GNOME. Home Page: http://gajim.org Downloads: http://www.gajim.org/downloads.php New in Gajim 0.8: # Avatars (JEP-0153) # Chat state notifications aka. typing notification (JEP-0085) # Bookmark storage (JEP-0048) # File Transfer (JEP-0096) # Major changes to adhere to GNOME HIG # Complete vcard fields support # New and better user interface for chat and groupchat windows # SRV capabilities and custom hostname/port # Many improvements in group chat and IRC emulation (eg. nick # autocompletation and cycling) # Gajim can now send and receive single messages # New iconsets and new dialog for customizing the user interface # Mouseover information for contacts in the roster window (aka # tooltips) # DBus Capabilities. Now Gajim can be remote controlled # Now you can lookup a word in Wikipedia, dictionary or in # search engine # XML Console # Authenticating HTTP Requests via XMPP (JEP-0070) # Notification Area Icon (aka. trayicon) support in Windows # Norwegian Czech translations -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: while c = f.read(1)
On 18 Aug 2005 22:21:53 -0700, Greg McIntyre [EMAIL PROTECTED] wrote: I have a Python snippet: f = open(blah.txt, r) while True: c = f.read(1) if c == '': break # EOF # ... work on c Is some way to make this code more compact and simple? It's a bit spaghetti. This is what I would ideally like: f = open(blah.txt, r) while c = f.read(1): # ... work on c How about (untested): for c in iter((lambda f=open('blah.txt', 'r'): f.read(1)), ''): # ... work on c (if c=='': break functionality courtesy of iter(f, sentinel) form above) Of course, reading characters one by one is not very efficient, so if the file is reasonably sized, you might just want to read the whole thing and iterate through it, something like for c in open('blah.txt').read(): # ... work on c But I get a syntax error. while c = f.read(1): ^ SyntaxError: invalid syntax And read() doesn't work that way anyway because it returns '' on EOF and '' != False. If I try: f = open(blah.txt, r) while (c = f.read(1)) != '': # ... work on c I get a syntax error also. :( Is this related to Python's expression vs. statement syntactic separation? How can I be write this code more nicely? Yes, it is related as you suspect. I'll leave it to you to make a chunk-buffering one-liner for huge files that iterates by characters, if one-liners turn you on. Otherwise it is easy to write a generator that will do it. Byt the time I post this, someone will probably have done it ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: while c = f.read(1)
Greg McIntyre wrote: I have a Python snippet: f = open(blah.txt, r) while True: c = f.read(1) if c == '': break # EOF # ... work on c Is some way to make this code more compact and simple? It's a bit spaghetti. That's not spaghetti. Not even close. In any case, is there a reason you are reading one character at a time instead of reading the contents of the file into memory and iterating over the resulting string? f = open('blah.txt', 'r') text = f.read() f.close() for c in f: # ... If you must read one character at a time, def reader(fileobj, blocksize=1): Return an iterator that reads blocks of a given size from a file object until EOF. # Note that iter() can take a function to call repeatedly until it # receives a given sentinel value, here ''. return iter(lambda: fileobj.read(blocksize), '') f = open('blah.txt', 'r') try: for c in reader(f): # ... finally: f.close() -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: certificate-based authentication (Martin v. L?wis)
I'm using Python version 2.2 - the SafeTransport class in it's xmlrpclib doesn't have a 'get_host_info' method. Which version were you referring to? I was looking at the HEAD revision in CVS. That feature was apparently released with Python 2.3. Still, httplib supports client certificates since Python 1.6, so you should be able to extend SafeTransport even in 2.2. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: while c = f.read(1)
Quoth Greg McIntyre [EMAIL PROTECTED]: | I have a Python snippet: | | f = open(blah.txt, r) | while True: | c = f.read(1) | if c == '': break # EOF | # ... work on c | | Is some way to make this code more compact and simple? It's a bit | spaghetti. Actually I'd make it a little less compact -- put the break on its own line -- but in any case this is fine. It's a natural and ordinary way to express this in Python. ... | But I get a syntax error. | | while c = f.read(1): |^ | SyntaxError: invalid syntax | | And read() doesn't work that way anyway because it returns '' on EOF | and '' != False. If I try: This is the part I really wanted to respond to. Python managed without a False for years (and of course without a True), and if the introduction of this superfluous boolean type really has led to much of this kind of confusion, then it was a bad idea for sure. The condition that we're looking at here, and this is often the way to look at conditional expressions in Python, is basically something vs. nothing. In this and most IO reads, the return value will be something, until at end of file it's nothing. Any type of nothing -- '', {}, [], 0, None - will test false, and everything else is true. Of course True is true too, and False is false, but as far as I know they're never really needed. You are no doubt wondering when I'm going to get to the part where you can exploit this to save you those 3 lines of code. Sorry, it won't help with that. | Is this related to Python's expression vs. statement syntactic | separation? How can I be write this code more nicely? Yes, exactly. Don't worry, it's nice as can be. If this is the worst problem in your code, you're far better off than most of us. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: while c = f.read(1)
Greg McIntyre wrote: I have a Python snippet: f = open(blah.txt, r) while True: c = f.read(1) if c == '': break # EOF That could read like this if not c: break # EOF # see below for comments on what is true/false # ... work on c Is some way to make this code more compact and simple? It's a bit spaghetti. Not at all, IMHO. This is a simple forward-branching exit from a loop in explicable circumstances (EOF). It is a common-enough idiom that doesn't detract from readability understandability. Spaghetti is like a GOTO that jumps backwards into the middle of a loop for no discernable reason. This is what I would ideally like: f = open(blah.txt, r) while c = f.read(1): # ... work on c But I get a syntax error. while c = f.read(1): ^ SyntaxError: invalid syntax And read() doesn't work that way anyway because it returns '' on EOF and '' != False. You have a bit of a misunderstanding here that needs correcting: In if blah and while blah, blah is NOT restricted to being in (True, False). See section 5.10 of the Python Reference Manual: In the context of Boolean operations, and also when expressions are used by control flow statements, the following values are interpreted as false: None, numeric zero of all types, empty sequences (strings, tuples and lists), and empty mappings (dictionaries). All other values are interpreted as true. ... AND it's about time that list is updated to include False explicitly -- save nitpicking arguments about whether False is covered by numeric zero of all types :-) If I try: f = open(blah.txt, r) while (c = f.read(1)) != '': # ... work on c I get a syntax error also. :( Is this related to Python's expression vs. statement syntactic separation? How can I be write this code more nicely? Thanks How about for c in f.read(): ? Note that this reads the whole file into memory (changing \r\n to \n on Windows) ... performance-wise for large files you've spent some memory but clawed back the rather large CPU time spent doing f.read(1) once per character. The more nicely factor improves outasight, IMHO. Mild curiosity: what are you doing processing one character at a time that can't be done with a built-in function, a standard module, or a 3rd-party module? -- http://mail.python.org/mailman/listinfo/python-list
Re: while c = f.read(1)
Bengt Richter wrote: On 18 Aug 2005 22:21:53 -0700, Greg McIntyre [EMAIL PROTECTED] wrote: I have a Python snippet: f = open(blah.txt, r) while True: c = f.read(1) if c == '': break # EOF # ... work on c Is some way to make this code more compact and simple? It's a bit spaghetti. This is what I would ideally like: f = open(blah.txt, r) while c = f.read(1): # ... work on c How about (untested): for c in iter((lambda f=open('blah.txt', 'r'): f.read(1)), ''): # ... work on c :-) Bengt, did you read on to the bit where the OP wanted to do it more nicely? YMMV, but I think you've strayed into pas devant les enfants territory. (-: Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Implementing class methods in C
I think you'd need to write a C++ class that has the methods you want to implement in C++, then wrap that with SWIG, then inherit from that, though multiple inheritance if you also need functions from a base Python class. The PyQt people use SIP I think, instead of SWIG, might be useful to look into that too too. Adriaan. [EMAIL PROTECTED] 08/18/05 6:42 pm Nope, it still doesn't work. Anyway, that's not exactly what i want, since i want func2 to be accessible from all instances of Test() Naveen On Thu, 18 Aug 2005, Jeremy Moles wrote: I honestly don't know the answer to this and I am entirely guessing but--does it work without using the new module? That is: import _test class Foo: pass foo = Foo() foo.bar = _test.func2 foo.bar() On Thu, 2005-08-18 at 12:09 -0400, [EMAIL PROTECTED] wrote: I am having a problem implementing some methods of a python class in C. The class is defined in python, but I would like to rewrite some methods in c. Here is an example of what I want to do: file _test.c: #include Python.h static PyObject func2(PyObject *self, PyObject *args) { if (self == NULL) { PyErr_SetString(PyExc_SystemError, self is NULL); return NULL; } // Parse arguments if (!PyArg_ParseTuple(args, )) { return NULL; } Py_INCREF(Py_None); return Py_None; } static PyMethodDef TestMethods[] = { {func2, func2, METH_VARARGS, func2.}, {NULL, NULL, 0, NULL} /* Sentinel */ }; PyMODINIT_FUNC init_test(void) { (void) Py_InitModule(_test, TestMethods); } test.py: class Test: def func1(self): print I am in func 1 import _test import new Test.func2 = new.instancemethod(_test.func2, None, Test) del(new) t = Test() t.func2() When I run test.py, I get a SystemError exception (which is what I raise if self is NULL). I think my confusion lies in the use of PyObject* self in the function declaration. Shouldn't this be set to point to the instance of class Test that I am calling it from? Am I misunderstanding the purpose of PyObject* self? Thanks. Naveen - Naveen Michaud-Agrawal Program in Molecular Biophysics Johns Hopkins University (410) 614 4435 -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: time.clock() problem under linux (precision=0.01s)
One of the limits of at least IBM compatible PC's is that in general they are not more accurate as about 1/64 th of a second if I recall correctly. I think this is the default tick size of the BIOS clock. Next to that the BIOS clock itself doesn't need to be very accurate, I can easily drift like an hour a year. Oh, and on top of that: If you are in a multi taksing operating system this complicates matters even further. This explains it very well: http://www.beaglesoft.com/mainfaqclock.htm Adriaan. Szabolcs Nagy [EMAIL PROTECTED] 08/18/05 1:07 pm I have to measure the time of a while loop, but with time.clock i always get 0.0s, although python manual sais: this is the function to use for benchmarking Python or timing algorithms So i tested timer functions capabilities with a short script: import time import os def test_timer_func(func): print 'min time-time: %.10f'%min(abs(func()-func()) for i in xrange(10**5)) print 'max time-time: %.10f'%max(abs(func()-func()) for i in xrange(10**5)) dt = 0.0 loopcount = 0 t = func() while dt==0.0: dt = func() - t loopcount += 1 print min measurable loop time : %.10f%dt print 'loopcount while dt==0 :',loopcount print '\n time.clock()' test_timer_func(time.clock) print '\n time.time()' test_timer_func(time.time) print '\n os.times()' ot = os.times test_timer_func(lambda:ot()[4]) My output is: time.clock() min time-time: 0.00 max time-time: 0.01 min measurable loop time : 0.01 loopcount while dt==0 : 2703 time.time() min time-time: 0.019073 max time-time: 0.460148 min measurable loop time : 0.050068 loopcount while dt==0 : 1 os.times() min time-time: 0.00 max time-time: 0.010007 min measurable loop time : 0.009998 loopcount while dt==0 : 2515 So the precision of time.clock is 0.01s under my ubuntu linux system, which means it's not suitable for benchmarking. (i want to benchmark the fps in my pygame+pyode program and it needs at least 0.001s precision) time.time seems much better solution, but python manual sais: not all systems provide time with a better precision than 1 second Should i use time.clock or time.time to be more crossplatform? Is time.time ok for windows? (time()-time() != 0.0) nszabolcs -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: python html
Steve Young wrote: Hi, I am looking for something where I can go through a html page and make change the url's for all the links, images, href's, etc... easily. If anyone knows of something, please let me know. Thanks. BeautifulSoup or PyMeld Lorenzo -- http://mail.python.org/mailman/listinfo/python-list
Database of non standard library modules...
Is there an online database of non standard library modules for Python? Quite often people who email this list are after a module to do a certain task. If it doesn't exist I think that an online database, to which people could add details of modules, and which people could search, would be an extremely valuable resource. Just wondering if anyone could tell me if something like this exists (probably does), and if not, I'll get to work :) Cheers Jon -- http://mail.python.org/mailman/listinfo/python-list
Re: Database of non standard library modules...
Jon Hewer wrote: Is there an online database of non standard library modules for Python? http://cheeseshop.python.org/pypi -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Problem (or even bug?) with Tkinter
Here's a strange one in Tkinter that has me stumped: (I'm running python 2.4 on Suse Linux 9.3 64bit) I'm trying to make a set of Entry widgets with Label widgets to the left of each one, using the grid layout. If I make and grid the Label *before* the Entry then the Entry widget doesn't seem to work - it lets me put the cursor in it, but I can't type! See example code below. Is this just me doing something really really silly, or is there a bug here? I'm inclined to think the latter. I've been developing with python 2.4 on Suse Linux 9.3 64bit. I've just tested it on a Win2k machine witih python 2.3 and can type into both Entry widgets. regards Matt --- #!/usr/bin/env python import Tkinter class ProblemGUI(object): def __init__(self): super(ProblemGUI, self).__init__() self.window = Tkinter.Tk() self.window.title(Try typing into both Entry widgets) # declare and grid Entry widget before Label widget self.entry1 = Tkinter.Entry(self.window) self.entry1.grid(row=0, column=1) self.label1 = Tkinter.Label(self.window, text=CAN WRITE -) self.label1.grid(row=0,column=0) # declare and grid Label widget before Entry widget self.label2 = Tkinter.Label(self.window, text=CAN'T WRITE -) self.label2.grid(row=1,column=0) self.entry2 = Tkinter.Entry(self.window) self.entry2.grid(row=1, column=1) x=ProblemGUI() x.window.mainloop() -- | Matt Hammond | RD Engineer, BBC Research and Development, Tadworth, Surrey, UK. -- http://mail.python.org/mailman/listinfo/python-list
global interpreter lock
Hi all, is true parallelism possible in python ? or atleast in the coming versions ? is global interpreter lock a bane in this context ? regards, KM -- http://mail.python.org/mailman/listinfo/python-list
Re: global interpreter lock
km [EMAIL PROTECTED] writes: is true parallelism possible in python ? or atleast in the coming versions ? is global interpreter lock a bane in this context ? http://poshmodule.sf.net -- http://mail.python.org/mailman/listinfo/python-list
Re: how do i add a new path into sys.path?
James Sungjin Kim wrote: Steve Holden wrote: sys.path.append(rC:\Temp) In this case, do I need to save the refined path, i.e, the original paths + the new path (rC:\Temp), by using some command in order to use it permanently. if yes, it would be greatly appreciated to noitce the correspoding command and the usage of it. -James The method I outlined works only for the duration of a single program run, because the sys.path variable is set up each time you run the Python interpreter. You need to look at the suggestions you've had for setting the PYTHONPATH environment variable to effect changes to all future Python execution. Essentially this is most usually done in the My Computer - Properties dialog: click the environment variables button and create a new (all-users or private, depending on your needs) environment variable called PYTHONPATH containing a semicolon-separated list of directories the interpreter should add to the path. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python jobs (was Re: Python for Webscripting (like PHP))
Aahz wrote: In article [EMAIL PROTECTED], Steve Holden [EMAIL PROTECTED] wrote: There's informal evidence that the Python secret is getting out. Sharpen up your resumes, guys, you may not have to limit Python to home usage soon :-) OTOH, the big sucking sound from Google and Yahoo (plus other places like Ironport) is making it more difficult to hire Python programmers in the Bay Area... Not to mention the large Python gravity field a few hundred miles South emanating from Industrial Light and Magic. But don;t expect Google and Yahoo suck to be a popular compaint ;-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: global interpreter lock
Paul Rubin wrote: km [EMAIL PROTECTED] writes: is true parallelism possible in python ? or atleast in the coming versions ? is global interpreter lock a bane in this context ? http://poshmodule.sf.net Is posh maintained? The page mentions 2003 as the last date. -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list
Re: Database of non standard library modules...
Robert Kern wrote: Jon Hewer wrote: Is there an online database of non standard library modules for Python? http://cheeseshop.python.org/pypi While cheeseshop might resonate with the Monty Python fans I have to say I think the name sucks in terms of explaining what to expect. If I ask someone where I can find a piece of code and the direct me to the cheese shop, I might look for another language. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: global interpreter lock
Robin Becker [EMAIL PROTECTED] writes: http://poshmodule.sf.net Is posh maintained? The page mentions 2003 as the last date. Dunno, and I suspect not. I've been wondering about it myself. -- http://mail.python.org/mailman/listinfo/python-list
Python on Palm??
Is there some implementation of Python that runs on Palm OS? I've found Python to Palm Pilot Port http://www.isr.uci.edu/projects/sensos/python/ and Pippy http://sourceforge.net/projects/pippy which both seem to be based on Python 1.5 Is there some implementation that implements later versions of Python? jem -- http://mail.python.org/mailman/listinfo/python-list
Re: while c = f.read(1)
On 18 Aug 2005 22:21:53 -0700 Greg McIntyre wrote: I have a Python snippet: f = open(blah.txt, r) while True: c = f.read(1) if c == '': break # EOF # ... work on c Is some way to make this code more compact and simple? It's a bit spaghetti. import itertools f = open(blah.txt, r) for c in itertools.chain(*f): print c # ... The f is iterable itself, yielding a new line from the file every time. Lines are iterable as well, so the itertools.chain iterates through each line and yields a character. -- jk -- http://mail.python.org/mailman/listinfo/python-list
Re: while c = f.read(1)
[EMAIL PROTECTED] writes: import itertools f = open(blah.txt, r) for c in itertools.chain(*f): print c # ... The f is iterable itself, yielding a new line from the file every time. Lines are iterable as well, so the itertools.chain iterates through each line and yields a character. But that can burn an unlimited amount of memory if there are long stretches of the file with no newlines. There's no real good way around ugly code. -- http://mail.python.org/mailman/listinfo/python-list
VIAGRRÁ-Good for your life
Hello, Welto PharmcyByMail ST0RE- Save huge 70% on all the 0rders with us.come We are there whionly stoch gives this great deal to you! VlALLlS VALy other drugplAGRRA ClUUM and mans in our sho r NEW PRlCESCheck out ou Have a nice day. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem (or even bug?) with Tkinter
On Fri, 19 Aug 2005 09:53:20 +0100, Matt Hammond [EMAIL PROTECTED] wrote: Here's a strange one in Tkinter that has me stumped: (I'm running python 2.4 on Suse Linux 9.3 64bit) I'm trying to make a set of Entry widgets with Label widgets to the left of each one, using the grid layout. If I make and grid the Label *before* the Entry then the Entry widget doesn't seem to work - it lets me put the cursor in it, but I can't type! See example code below. Is this just me doing something really really silly, or is there a bug here? I tested with Python 2.1 on Mandrake Linux 8.0 and it works fine. My tcl/tk version is 8.3.4 Do you know the tcl/tk version you have? If you don't, you can get it via: from Tkinter import Tk() root = Tk() root.tk.eval('puts $tk_patchLevel') I suspect a bug at tcl level. So can you execute the following tcl script: --- entry .en1 grid .en1 -row 0 -column 1 label .lb1 -text CAN WRITE - grid .lb1 -row 0 -column 0 label .lb2 -text CAN'T WRITE - grid .lb2 -row 1 -column 0 entry .en2 grid .en2 -row 1 -column 1 --- It is exactly the same as yours in tcl syntax. To execute it, just save it to the file script.tcl and type in a shell: wish script.tcl (The wish command may include a version number, such as wish8.4) If the script above shows the same behaviour as your Python script, then it's not Tkinter's fault, but tk's. You should then report the bug to comp.lang.tcl. HTH -- python -c print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-']) -- http://mail.python.org/mailman/listinfo/python-list
Re: Implementing class methods in C
[EMAIL PROTECTED] wrote: Am I misunderstanding the purpose of PyObject* self? No. I think you do everything right, but it still doesn't work. I have tried to implement it in Python: _test.py: def func2(self, *args): print type(self) print args then all of this works: import _test class Test1: func2 = _test.func2 class Test2: pass Test2.func2 = _test.func2 class Test3: pass import new Test3.func2 = new.instancemethod(_test.func2, None, Test3) del new Test1().func2(1, 2, 3) Test2().func2(1, 2, 3) Test3().func2(1, 2, 3) If you implement _test in C, works none of the above. The only difference I can see is that: type(_test.func2) type 'function' is for Python implemented function and type(_test.func2) type 'builtin_function_or_method' for C implementation I would really like to know the answer too. How do you implement some methods in C without subclassing ? BranoZ -- http://mail.python.org/mailman/listinfo/python-list
Re: Database of non standard library modules...
Steve Holden [EMAIL PROTECTED] writes: Robert Kern wrote: Jon Hewer wrote: Is there an online database of non standard library modules for Python? http://cheeseshop.python.org/pypi While cheeseshop might resonate with the Monty Python fans I have to say I think the name sucks in terms of explaining what to expect. If I ask someone where I can find a piece of code and the direct me to the cheese shop, I might look for another language. +1 Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for Webscripting (like PHP)
Yes the stdlib offers all the basic functions, but why work so hard? Get CherryPy (http://www.cherrypy.org) and relax a bit. You'll be able to concentrate on Python for the backend, HTML for the frontend, without a lot of directory-diddling. Also, check out http://www-128.ibm.com/developerworks/opensource/library/os-cherrypy/index.html#main for a nice, fresh slice. Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: while c = f.read(1)
[EMAIL PROTECTED] wrote: import itertools f = open(blah.txt, r) for c in itertools.chain(*f): print c # ... The f is iterable itself, yielding a new line from the file every time. Lines are iterable as well, so the itertools.chain iterates through each line and yields a character. As far as I can tell, that code is just going to read the whole file in when Python does the *arg expansion. What's the point? -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: Database of non standard library modules...
Robert Kern wrote: Jon Hewer wrote: Is there an online database of non standard library modules for Python? http://cheeseshop.python.org/pypi Actually, there are many other Python source code and apps repositories. Here a few links, just in case you was not aware of them: http://mu.arete.cc/pcr/ http://www.vex.net/parnassus/ http://pythonical.sourceforge.net/ http://www.strout.net/python/intro.html CU --- Alessandro Bottoni -- http://mail.python.org/mailman/listinfo/python-list
Re: while c = f.read(1)
On 19 Aug 2005 03:43:31 -0700 Paul Rubin wrote: [EMAIL PROTECTED] writes: import itertools f = open(blah.txt, r) for c in itertools.chain(*f): But that can burn an unlimited amount of memory if there are long stretches of the file with no newlines. There's no real good way around ugly code. I agree. Moreover, in fact, it is the same as just for c in f.read(): # ... -- jk -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for Webscripting (like PHP)
I like the look of cheeryPy - snyone know if its easy to get it running on top of Apache? Thanks On 19 Aug 2005 04:10:23 -0700, paron [EMAIL PROTECTED] wrote: Yes the stdlib offers all the basic functions, but why work so hard? Get CherryPy (http://www.cherrypy.org) and relax a bit. You'll be able to concentrate on Python for the backend, HTML for the frontend, without a lot of directory-diddling. Also, check out http://www-128.ibm.com/developerworks/opensource/library/os-cherrypy/index.html#main for a nice, fresh slice. Ron -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for Webscripting (like PHP)
'cherryPy' even On 8/19/05, Jon Hewer [EMAIL PROTECTED] wrote: I like the look of cheeryPy - snyone know if its easy to get it running on top of Apache? Thanks On 19 Aug 2005 04:10:23 -0700, paron [EMAIL PROTECTED] wrote: Yes the stdlib offers all the basic functions, but why work so hard? Get CherryPy (http://www.cherrypy.org) and relax a bit. You'll be able to concentrate on Python for the backend, HTML for the frontend, without a lot of directory-diddling. Also, check out http://www-128.ibm.com/developerworks/opensource/library/os-cherrypy/index.html#main for a nice, fresh slice. Ron -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for Webscripting (like PHP)
Yes, there's a tutorial about that -- there are several options depending on the URL structure you want to expose, and your version of Apache. None of them are torturous, though. Start at http://www.cherrypy.org/wiki/CherryPyProductionSetup and follow the links down. Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for Webscripting (like PHP)
Ah cool, thanks, i hadn't spotted that page :) On 19 Aug 2005 04:51:06 -0700, paron [EMAIL PROTECTED] wrote: Yes, there's a tutorial about that -- there are several options depending on the URL structure you want to expose, and your version of Apache. None of them are torturous, though. Start at http://www.cherrypy.org/wiki/CherryPyProductionSetup and follow the links down. Ron -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Database of non standard library modules...
[Steve] While cheeseshop might resonate with the Monty Python fans I have to say I think the name sucks in terms of explaining what to expect. If I ask someone where I can find a piece of code and the direct me to the cheese shop, I might look for another language. +1 -- Richie Hindle [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Database of non standard library modules...
On Fri, 19 Aug 2005 10:33:16 +0100, Steve Holden [EMAIL PROTECTED] wrote: While cheeseshop might resonate with the Monty Python fans I have to say I think the name sucks in terms of explaining what to expect. If I ask someone where I can find a piece of code and the direct me to the cheese shop, I might look for another language. Point them at the Python Package Index: http://www.python.org/pypi, which is just proxying for cheeseshop.python.org. Many names were brought up (I think all this discussion was on the catalog SIG), but none of them was widely liked. So Richard Jones, the maintainer, got to choose. --amk -- http://mail.python.org/mailman/listinfo/python-list
Re: how do i add a new path into sys.path?
Steve Holden wrote: The method I outlined works only for the duration of a single program run, because the sys.path variable is set up each time you run the Python interpreter. You need to look at the suggestions you've had for setting the PYTHONPATH environment variable to effect changes to all future Python execution. Or, often better and cleaner, use .pth files as described in the documentation for the standard library site module. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Python on Palm??
Kalle Anke wrote: Is there some implementation of Python that runs on Palm OS? I've found Python to Palm Pilot Port http://www.isr.uci.edu/projects/sensos/python/ and Pippy http://sourceforge.net/projects/pippy which both seem to be based on Python 1.5 Is there some implementation that implements later versions of Python? This is asked fairly frequently, and you can easily search the list archives using Google Groups to see more detailed answers than the following one: If you want to write real Palm applications (i.e. which have access to features provided by the operating system such as PDB files or GUI elements), the answer is no, not yet, though people are still working on very early phases of projects that might someday get there. My personal advice after saying that is to investigate Plua (Palm version of Lua) which does provide pretty good access to the Palm OS and which has a similar enough feel to Python that I don't mind using it. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Adobe COM with Python
I'm wanting to automate Adove Acrobat Reader using Com thru Python and win32com, but i can't find any documentation for the Adobe stuff? Has anyone done anything with Acrobat COM ? I've searched Google groups and the web but am unable to find anything. Thanks Andy -- http://mail.python.org/mailman/listinfo/python-list
Re: up to date books?
John Salerno wrote: These all seem to be focused on Java though. I think C# is close enough to Java when it comes to the issues discussed here, that you can read the texts and more or less think C# when you read Java... gene tani wrote: Start here: http://naeblis.cx/rtomayko/2004/12/15/the-static-method-thing http://dirtsimple.org/2004/12/java-is-not-python-either.html http://ischenko.blogspot.com/2005/02/java-may-not-be-that-bad-after-all.html and maybe poke around ehre to learn about language design, how people define typing, etc http://www.artima.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: up to date books?
John Salerno wrote: Just one more quick question: I'm basically learning programming for fun, and I'm concentrating on C# right now. Python seems interesting, but I was wondering if I should even bother. Would it supplement C# in any way, or can C# do everything Python can? Python is an excellent tool in any programmers toolbox. No one language is ideal for every task, but Python very often provides a more rapid solution to your problem than other languages do. Particularly for small problems. It's common to use Python to solve a problem in 3 minutes that would take 10 or 30 minutes to solve in some other way. It's also great for building something in 3 man-months instead of 3 man-years, but you need more time to verify that claim! ;^) If you need a GUI for some simple task, it might often be more convenient to use something like Excel or VB. I haven't used MS's C# environment, so I can't compare with that, but it's often just a bad habit to build captive user interfaces for every task we want to solve. It certainly makes it much more difficult to make modular and reusable software. Most Python programs I write work both as standalone programs and as modules that other programs can use. This versatility basically costs one line of code. If I was a professional C# developer, I'm pretty sure I'd use Python quite a bit. As a professional C++ programmer and database developer, I've used Python to manage tests, find and repair broken data in mission critical production systems, automate database administration tasks such as upgrading multiple databases, extracting, converting and copying data, create database reports, post-process generated source code, analyze large software systems and databases etc etc. Actually, during seven years as an independent consultant, I found good use for Python with every client. -- http://mail.python.org/mailman/listinfo/python-list
Save Binary data.
Hello All. I have a program that downloads 'gigabytes' of Axis NetCam photos per day. Right now, I set up the process to put the images into a queue, and every 30 or so seconds, 'pop' them from the queue and save them to disc. I save them as individual files. I think that I'd like to modify it to save into one file 100-200 images, so that I don't have directories with 50,000-90,000 frames before handing that off to a DivX Encoder. I don't know if I need to use something like cPickle, or maybe just save them as a binary data file (which would be a temp file until later in the day when I open it to begin the encoding process.) Can someone please help me with some direction? Thank you! Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem (or even bug?) with Tkinter
Thanks for that. I've tested your script and it seems to have the same problem, so I'll post your example across in comp.lang.tcl as you suggest. Seems I'm running tcl/tk 8.4.9, and wish 8.4 cheers Matt I suspect a bug at tcl level. So can you execute the following tcl script: --- entry .en1 grid .en1 -row 0 -column 1 label .lb1 -text CAN WRITE - grid .lb1 -row 0 -column 0 label .lb2 -text CAN'T WRITE - grid .lb2 -row 1 -column 0 entry .en2 grid .en2 -row 1 -column 1 --- It is exactly the same as yours in tcl syntax. To execute it, just save it to the file script.tcl and type in a shell: wish script.tcl -- | Matt Hammond | RD Engineer, BBC Research and Development, Tadworth, Surrey, UK. -- http://mail.python.org/mailman/listinfo/python-list
Re: python html
Steve Young wrote: Hi, I am looking for something where I can go through a html page and make change the url's for all the links, images, href's, etc... easily. If anyone knows of something, please let me know. Thanks. You might try XIST (http://www.livinglogic.de/Python/xist) Code might look like this: from ll.xist import xsc, parsers node = parsers.parseURL(http://www.python.org/;, tidy=True) for link in node//xsc.URLAttr: link[:] = unicode(link).replace( http://www.python.org/;, http://www.perl.org/; ) print node.asBytes() Bye, Walter Dörwald -- http://mail.python.org/mailman/listinfo/python-list
Netware Python?
Hello all. Looking, I have not found a version of Python which runs on Netware by Novell. I wonder, since Java there is a Java for Netware, is this where Jython would come in as useful, to be able to use a Python script where Java is installed? I'm interested in the threaded heartbeat program in the cookbook for my Netware environment, to be connected to a nice graphical front end on my Win32 station, to know when servers are up or down (well, since Netware is hardly ever down, when the WAN links are up or down) -dave -- http://mail.python.org/mailman/listinfo/python-list
Re: Adobe COM with Python
Andy W wrote: I'm wanting to automate Adove Acrobat Reader using Com thru Python and win32com, but i can't find any documentation for the Adobe stuff? Has anyone done anything with Acrobat COM ? I've searched Google groups and the web but am unable to find anything. I have not hacked Acrobat yet, but done a bit with InDesign - Adobe's documentation is less than perfect, but still pretty good. You might look at http://partners.adobe.com/public/developer/acrobat/sdk/index_doc.html#js - in InDesign I could easily map the methods and attributes from the JS documentation to COM calls (the JS members start with lowercase - e.g. 'properties' -, while COM need uppercase - 'Properties'). -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: while c = f.read(1)
Op 2005-08-19, Donn Cave schreef [EMAIL PROTECTED]: Quoth Greg McIntyre [EMAIL PROTECTED]: | I have a Python snippet: | | f = open(blah.txt, r) | while True: | c = f.read(1) | if c == '': break # EOF | # ... work on c | | Is some way to make this code more compact and simple? It's a bit | spaghetti. Actually I'd make it a little less compact -- put the break on its own line -- but in any case this is fine. It's a natural and ordinary way to express this in Python. ... | But I get a syntax error. | | while c = f.read(1): |^ | SyntaxError: invalid syntax | | And read() doesn't work that way anyway because it returns '' on EOF | and '' != False. If I try: This is the part I really wanted to respond to. Python managed without a False for years (and of course without a True), and if the introduction of this superfluous boolean type really has led to much of this kind of confusion, then it was a bad idea for sure. IMO the confusion is the result of True and False appearing late. IMO having python interpret None, '', (), {} and [] as false in a conditional context goes against the spirit of: In the face of ambiguity, refuse the temptation to guess. The condition that we're looking at here, and this is often the way to look at conditional expressions in Python, is basically something vs. nothing. In this and most IO reads, the return value will be something, until at end of file it's nothing. Any type of nothing -- '', {}, [], 0, None - will test false, But '', {}, [] and () are not nothing. They are empty containers. And 0 is not nothing either it is a number. Suppose I have a variable that is either None if I'm not registered and a registration number if I am. In this case 0 should be treated as any other number. Such possibilities, make me shy away from just using 'nothing' as false and writing out my conditionals more explicitly. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: Adobe COM with Python
What i want to do is use, python COM to fireup Adobe and print the pdf file to a printer. import win32com.client import pythoncom pythoncom.CoInitializeEx(pythoncom.COINIT_APARTMENTTHREADED) acro = win32com.client.DispatchEx('PDF.PdfCtrl.1') The above does not work, Do i need to install the SDK as well ? I'm new to this COM stuff as you can guess. Benjamin Niemann wrote: Andy W wrote: I'm wanting to automate Adove Acrobat Reader using Com thru Python and win32com, but i can't find any documentation for the Adobe stuff? Has anyone done anything with Acrobat COM ? I've searched Google groups and the web but am unable to find anything. I have not hacked Acrobat yet, but done a bit with InDesign - Adobe's documentation is less than perfect, but still pretty good. You might look at http://partners.adobe.com/public/developer/acrobat/sdk/index_doc.html#js - in InDesign I could easily map the methods and attributes from the JS documentation to COM calls (the JS members start with lowercase - e.g. 'properties' -, while COM need uppercase - 'Properties'). -- http://mail.python.org/mailman/listinfo/python-list
Newbie Question
I have a file that contains many lines, each of which consists of a string of comma-separated variables, mostly floats but some strings. Each line looks like an obvious tuple to me. How do I save each line of this file as a tuple rather than a string? Or, is that the right way to go? Thank you. Tom Strickland -- http://mail.python.org/mailman/listinfo/python-list
RE: Adobe COM with Python
[Andy W] | What i want to do is use, python COM to fireup Adobe and | print the pdf | file to a printer. If that's all you want to do, have a look at this: http://timgolden.me.uk/python/win32_how_do_i/print.html Or you could try for a Ghostscript solution. (Additionally, I seem to remember that the Acrobat COM object is really only designed to work in Internet Explorer. That was a version or so ago -- of both -- so I may be off beam). TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Database of non standard library modules...
Steve Holden wrote: Robert Kern wrote: Jon Hewer wrote: Is there an online database of non standard library modules for Python? http://cheeseshop.python.org/pypi While cheeseshop might resonate with the Monty Python fans I have to say I think the name sucks in terms of explaining what to expect. If I ask someone where I can find a piece of code and the direct me to the cheese shop, I might look for another language. I think it's just meant to be a handy moniker. An acronym like CPAN doesn't exactly clear everything up in one shot, either, but at least other Perl users know what you mean when you say it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Module Name Conflicts
[EMAIL PROTECTED] wrote: I have a java program in a package called 'cmd'. This of course conflicts with the builtin python package of the same name. The thing is, I need to be able to import from both of these packages in the same script. I can import either one first, but any future attempt to import from cmd.* will look up the first cmd that was imported, so the second package is essentially eclipsed. I've tried fiddling with sys.path and sys.packageManager.searchPath, to no avail. To answer the obvious first suggestion, no I can't rename the java package to 'Cmd' or anything like that. Any ideas? -Smurf Never used it myself, but you can try to use the builtin 'imp' module. Python Library Reference 3.21 imp -- Access the import internals This module provides an interface to the mechanisms used to implement the import statement. It defines the following constants and functions: ... -- http://mail.python.org/mailman/listinfo/python-list
Re: GIS Related Scripting Issue
you might want to try http://forums.esri.com/forums.asp?c=93 and post in the geoprocessing section with code details Fredrik Lundh [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Mike Rose wrote: I am currently using ArcGIS 9.1 and was referred to this list to ask my question. I am using a python script to loop through a series of features, select all polygons that are within 5 miles, run statistics on those selected polygons, then append the values to a new database(dbf). I am not sure if I am going about this correctly or not, but my script is definitely not working. I am getting an error when it tries to append to the dbf. can you perhaps post the error message? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Adobe COM with Python
I wanting to print the PDF to a printer which is set to print to file, so efectively i end up with a ps file. so 1 pdf becomes 1 ps file Tim Golden wrote: [Andy W] | What i want to do is use, python COM to fireup Adobe and | print the pdf | file to a printer. If that's all you want to do, have a look at this: http://timgolden.me.uk/python/win32_how_do_i/print.html Or you could try for a Ghostscript solution. (Additionally, I seem to remember that the Acrobat COM object is really only designed to work in Internet Explorer. That was a version or so ago -- of both -- so I may be off beam). TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: global interpreter lock
On 2005-08-20, km [EMAIL PROTECTED] wrote: is true parallelism possible in python? No, not for some values of true parallelism. or atleast in the coming versions? Not that I'm aware of. is global interpreter lock a bane in this context? In what context? -- Grant Edwards grante Yow! I think I'll do BOTH at if I can get RESIDUALS!! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: python html
I do exactly that in my Python CGI proxy (approx). I wrote a very simple parser called scraper.py that makes it easy. It won't choke on bad html either. http://www.voidspace.org.uk/python/recipes.shtml All the best, Fuzzyman http://www.voidspace.org.uk/python -- http://mail.python.org/mailman/listinfo/python-list
RE: Adobe COM with Python
[Andy W] | I wanting to print the PDF to a printer which is set to print | to file, | so efectively i end up with a ps file. | | so 1 pdf becomes 1 ps file It't not quite clear to me what you *want* to do as opposed to what actually happens when you try. If I understand, you have a PDF file, and you *want* to output it as a Postscript file. (And you want to automate that arrangement). If that's the case, I can think of two approaches, neither using COM -- which may be a valid third approach. The first is to use the possibly deprecated Acrobat Reader command-line switches to print a file and pass a file name. There's some information here: http://www.stillhq.com/ctpfaq/2002/03/c45.html#AEN103 and if you want to get hold of an older version of Acrobat, try oldversion.com The second is to use ghostscript from http://www.cs.wisc.edu/~ghost/ to generate a ps file from a pdf file. Hope that helps. TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Dr. Dobb's Python-URL! - weekly Python news and links (Aug 18)
QOTW: It seems to me that Java is designed to make it difficult for programmers to write bad code, while Python is designed to make it easy to write good code. -- Magnus Lycka Code attracts people that like to code. Tedious, repetitive c.l.py threads attract people that like to write tedious, repetitive c.l.py threads. -- Robert Kern Yes, commercial Python training *is* available: http://groups.google.com/group/comp.lang.python.announce/msg/f1bd9b8deac1cb39 You know how essential the Cookbook is. Filling a slightly different role is the Grimoire: http://the.taoofmac.com/space/Python/Grimoire The latest SPE features a remote, encrypted and embedded ... debugger ...: http://pythonide.stani.be Paul Dale convincingly advertises O'Reilly's Safari service: http://groups.google.com/group/comp.lang.python/browse_thread/thread/115a242dc77b0057/ Python is a superb vehicle for several niches generally thought exclusive to other languages, such as automation of Windows processes. Another too-little-known such strength is Python's adeptness with native Mac OS X applications: http://developer.apple.com/cocoa/pyobjc.html mensanator introduces enough of bit arithmetic to explain popcount and Hamming distance: http://groups.google.com/group/comp.lang.python/browse_thread/thread/e0716ffcf80af3a2/ PEP editors David Goodger and Barry Warsaw refine PEP organization: http://mail.python.org/pipermail/python-list/2005-August/294467.html Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. For far, FAR more Python reading than any one mind should absorb, much of it quite interesting, several pages index much of the universe of Pybloggers. http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog http://www.planetpython.org/ http://mechanicalcat.net/pyblagg.html comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/groups?oi=djqas_ugroup=comp.lang.python.announce Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous tradition early borne by Andrew Kuchling, Michael Hudson and Brett Cannon of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Kurt B. Kaiser publishes a weekly report on faults and patches. http://www.google.com/groups?as_usubject=weekly%20python%20patch Cetus collects Python hyperlinks. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://aspn.activestate.com/ASPN/Cookbook/Python Among several Python-oriented RSS/RDF feeds available are http://www.python.org/channews.rdf http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi http://python.de/backend.php For more, see http://www.syndic8.com/feedlist.php?ShowMatch=pythonShowStatus=all The old Python To-Do List now lives principally in a SourceForge reincarnation.
Re: Implementing class methods in C
If you implement _test in C, works none of the above. The only difference I can see is that: type(_test.func2) type 'function' is for Python implemented function and type(_test.func2) type 'builtin_function_or_method' for C implementation I would really like to know the answer too. How do you implement some methods in C without subclassing ? But the strange thing is if I use new.instancemethod the c function becomes bound (using my previous code for _test.c) import _test class Test: def func1(self): print In class +repr(self.__class__.__namd__) import new Test.func2 = new.instancemethod(_test.func2, None, Test) del new t = Test type(_test.func2) # returns type 'builtin_function_or_method' type(T.func1) # returns unbound method Test.func type(t.func1) # returns bound method Test.func of __main__.Test instance at 0x4eb4b8 type(T.func2) # returns built-in function func2 type(t.func2) # returns bound method Test.func2 of __main__.Test instance at 0x4eb4b8 So is seems like it is bound appropriately, but when called across the C/Python api the first argument (self) of func2 is not separated from the other arguments (and thus is not sent into the c function as PyObject* self, but instead as part of PyObject* args) -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie Question
look into the csv module. (for comma-separated-value text files.) Tom Strickland wrote: I have a file that contains many lines, each of which consists of a string of comma-separated variables, mostly floats but some strings. Each line looks like an obvious tuple to me. How do I save each line of this file as a tuple rather than a string? Or, is that the right way to go? Thank you. Tom Strickland -- http://mail.python.org/mailman/listinfo/python-list
RE: Newbie Question
Tom, Well, as one newbie to another, I tried this; x = '22,44,66,88,asd,asd,23,43,55' y = eval(x) y (22, 44, 66, 88, 'asd,asd', '23,43,55') given that x some how comes from a single line in your file. BTW, do you get the tutor list as well? My guess is that the 'experts' over here might prefer that the newbies go over there for stuff like this. And now, a question for the experts. Does anyone have a pointer as to why my code might be dangerous? I get the feeling that eval might not be a 'good' ( safe ) thing to use. Michael -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] n.org]On Behalf Of Tom Strickland Sent: Friday, August 19, 2005 10:05 AM To: python-list@python.org Subject: Newbie Question I have a file that contains many lines, each of which consists of a string of comma-separated variables, mostly floats but some strings. Each line looks like an obvious tuple to me. How do I save each line of this file as a tuple rather than a string? Or, is that the right way to go? Thank you. Tom Strickland -- http://mail.python.org/mailman/listinfo/python-list ___ The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Save Binary data.
Images are binary data, don't do anything to them just save them to files on disk in their binary format. The extra processing of pickling them isn't going to help. Directories with large numbers of files was a problem in FAT16 and FAT32 filesystems but not really a problem in NTFS or Linux (at least that I've found). Appending 100-200 images together into a single file will surely cut down on the number of files. A lot depends on what the next step in the process is expecting (e.g. individual files or a a stream of data). If it is individual files, you will have to split them back apart anyway so keeping them as individual files is a benefit. Larry Bates GMane Python wrote: Hello All. I have a program that downloads 'gigabytes' of Axis NetCam photos per day. Right now, I set up the process to put the images into a queue, and every 30 or so seconds, 'pop' them from the queue and save them to disc. I save them as individual files. I think that I'd like to modify it to save into one file 100-200 images, so that I don't have directories with 50,000-90,000 frames before handing that off to a DivX Encoder. I don't know if I need to use something like cPickle, or maybe just save them as a binary data file (which would be a temp file until later in the day when I open it to begin the encoding process.) Can someone please help me with some direction? Thank you! Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: Netware Python?
I'm not really up on Netware, but I believe that Netware's Open Enterprise Server is based on Suse Linux as the underlying OS, so Python should run there just fine. Google turned up the following that you might want to review: http://www.python.org/workshops/2000-01/proceedings/papers/clements/clements.html http://forge.novell.com/modules/xfmod/project/?jythonnwkit http://www.novell.com/products/openenterpriseserver/ Larry Bates GMane Python wrote: Hello all. Looking, I have not found a version of Python which runs on Netware by Novell. I wonder, since Java there is a Java for Netware, is this where Jython would come in as useful, to be able to use a Python script where Java is installed? I'm interested in the threaded heartbeat program in the cookbook for my Netware environment, to be connected to a nice graphical front end on my Win32 station, to know when servers are up or down (well, since Netware is hardly ever down, when the WAN links are up or down) -dave -- http://mail.python.org/mailman/listinfo/python-list
Re: Save Binary data.
GMane Python wrote: Hello All. I have a program that downloads 'gigabytes' of Axis NetCam photos per day. Right now, I set up the process to put the images into a queue, and every 30 or so seconds, 'pop' them from the queue and save them to disc. I save them as individual files. I think that I'd like to modify it to save into one file 100-200 images, so that I don't have directories with 50,000-90,000 frames before handing that off to a DivX Encoder. I don't know if I need to use something like cPickle, or maybe just save them as a binary data file (which would be a temp file until later in the day when I open it to begin the encoding process.) Can someone please help me with some direction? You could use the tarfile module to create a single file holding a arbitrary number of files - including compression, if you want, but if your images are JPEGs then further compression is mostly a waste of CPU cycles. You can extract the images later on with either a python script and tarfile or using the standard commandline tool 'tar'. If the images are uncompressed anyway, you could have a look at the netpbm suite and its fileformat (which is pretty simple, but uncompressed and would bloat JPEGs to a multiple of the original filesize) which supports 'image sequences'. Perhaps a DivX encoder could even support this fileformat directly as input. -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python jobs (was Re: Python for Webscripting (like PHP))
I'd love Python work, just like everyone else here. On a related topic, what's the policy/etiquette of posting a resume on here, or mentioning what kind of work you're looking for? And what's the policy in general for most newsgroups and mailing lists? -Greg On 8/19/05, Steve Holden [EMAIL PROTECTED] wrote: Aahz wrote: In article [EMAIL PROTECTED] , Steve Holden [EMAIL PROTECTED] wrote:There's informal evidence that the Python secret is getting out. Sharpenup your resumes, guys, you may not have to limit Python to home usagesoon :-) OTOH, the big sucking sound from Google and Yahoo (plus other places like Ironport) is making it more difficult to hire Python programmers in the Bay Area...Not to mention the large Python gravity field a few hundred miles South emanating from Industrial Light and Magic.But don;t expect Google and Yahoo suck to be a popular compaint ;-)regardsSteve--Steve Holden +44 150 684 7255+1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ --http://mail.python.org/mailman/listinfo/python-list -- Gregory PiñeroChief Innovation OfficerBlended Technologies(www.blendedtechnologies.com) -- http://mail.python.org/mailman/listinfo/python-list
Re: global interpreter lock
KM, I eagerly await the answer to this question as well. I'd love to see this explained in laymen's terms. From what I understand of this issue, your best bet for getting parrelism is to use whatever the OS provides and just have multiple python instances running... but then I didn't understand the articles I've read about this so don't listen to me. -Greg -- http://mail.python.org/mailman/listinfo/python-list
stdin - stdout
hi. i was wondering, what's the simplest way to echo the standard input to the standard output, with no modification. i came up with: ... while True: try: raw_input() except EOFError: break ... but i guess there must be a simpler way. using bash i simply do 'cat', *sigh*! bye max ps: in perl you ca do this: ... while ($line = STDIN) { print STDOUT ($line); } ... -- http://mail.python.org/mailman/listinfo/python-list
Re: stdin - stdout
2005/8/19, max(01)* [EMAIL PROTECTED]: hi. i was wondering, what's the simplest way to echo the standard input to the standard output, with no modification. i came up with: ... while True: try: raw_input() except EOFError: break ... but i guess there must be a simpler way. using bash i simply do 'cat', *sigh*! bye max ps: in perl you ca do this: ... while ($line = STDIN) { print STDOUT ($line); } ... Try this. import sys line = sys.stdin.readline() while line: sys.stdout.write(line) line = sys.stdin.readline() -- I like python! My Donews Blog: http://www.donews.net/limodou -- http://mail.python.org/mailman/listinfo/python-list
Re: global interpreter lock
km wrote: Hi all, is true parallelism possible in python ? or atleast in the coming versions ? is global interpreter lock a bane in this context ? No; maybe; and currently, not usually. On a uniprocessor system, the GIL is no problem. On multi- processor/core systems, it's a big loser. -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie Question
[EMAIL PROTECTED] wrote: x = '22,44,66,88,asd,asd,23,43,55' y = eval(x) y (22, 44, 66, 88, 'asd,asd', '23,43,55') And now, a question for the experts. I'm no expert, just experienced. Does anyone have a pointer as to why my code might be dangerous? Well, the smallest problem you have here is that you will get an SyntaxError exception on badly formated input. x = 'z,22,44,66,88,asd,asd,23,43,55' eval(x) NameError: name 'z' is not defined In worse case, somebody will send you a carefuly formated input that you will run blindy (just like in case of buffer overflows). CSV is easy with the module.. import csv cr = csv.reader((x,)) print cr.next() ['z', '22', '44', '66', '88', 'asd,asd', '23,43,55'] Usually, you will use the csv module, like this: import csv, sys for line in csv.reader(sys.stdin): # print line[3] BranoZ -- http://mail.python.org/mailman/listinfo/python-list
BeautifulSoup
I tried using BeautifulSoup to make changes to the url links on html pages, but when the page was displayed, it was garbled up and didn't look right (even when I didn't actually change anything on the page yet). I ran these steps in python to see what was up: from BeautifulSoup import BeautifulSoup from urllib2 import build_opener, Request req = Request('http://www.python.org/') f = build_opener().open(req) page = f.read() f.close() len(page) 12040 soup = BeautifulSoup() soup.feed(page) page2 = soup.renderContents() len(page2) 11889 I have version 2.1 of BeautifulSoup. It seems that other ppl have used BeautifulSoup and it works fine for them so I'm not sure what I'm doing wrong. Any help would be appreciated, thanks. -Steve Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs -- http://mail.python.org/mailman/listinfo/python-list
Re: stdin - stdout
On Fri, 19 Aug 2005 15:26:27 GMT, max(01)* [EMAIL PROTECTED] wrote: ps: in perl you ca do this: ... while ($line = STDIN) { print STDOUT ($line); } ... import fileinput import sys for line in fileinput.input(): sys.stdout.write(line) Regards, Dan -- Dan Sommers http://www.tombstonezero.net/dan/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie Question
Tom Strickland [EMAIL PROTECTED] wrote: I have a file that contains many lines, each of which consists of a string of comma-separated variables, mostly floats but some strings. Each line looks like an obvious tuple to me. How do I save each line of this file as a tuple rather than a string? Or, is that the right way to go? Depending on exactly what format you've got, either .split(',') on the line, or if this is insufficient look at the csv module. You'll then need some way of turning the list of strings both of these will give you into the mixed float/string tuple you want, which could be somewhat tedious. Without knowing what these lines look like, or what they represent, I can't begin to guess how you might go about it. Actually, I can -- I'd start by considering whether a dict might be more appropriate than a tuple and use csv.DictReader. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | Frankly I have no feelings towards penguins one way or the other \X/ |-- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie Question
Yes, eval of data from a file is rather risky. Suppose someone gave you a file containing somewhere in the middle: ... 22,44,66,88,asd,asd,23,43,55 os.system('rm -rf *') 33,47,66,88,bsd,bsd,23,99,88 ... This would delete all the files in your directory! The csv module mentioned above is the tool of choice for this task, especially if there are strings that could contain quotes or commas. Doing this right is not at all easy. If you really want to roll your own, and the data is KNOWN to be fixed and very restricted, you can do something like: myfile contains: 13,2,'the rain',2.33 14,2,'in spain',2.34 for l in open('myfile'): x,y,comment,height = l.split(',') x=int(x) y=int(y) height=int(height) comment=comment.strip(' ) # strip spaces and quotes from front and back but beware this will break if the comment contains commas. -- George -- http://mail.python.org/mailman/listinfo/python-list
Re: stdin - stdout
import sys for l in sys.stdin: sys.stdout.write(l) -- George -- http://mail.python.org/mailman/listinfo/python-list
Re: while c = f.read(1)
Antoon Pardon wrote: But '', {}, [] and () are not nothing. They are empty containers. And 0 is not nothing either it is a number. Suppose I have a variable that is either None if I'm not registered and a registration number if I am. In this case 0 should be treated as any other number. This is why None is a singleton:: if registration_number is None: # do one thing else: # do another In the OP's case, if file.read() had happened to return None instead of the empty string, he probably would've wanted to do the same thing. OTOH, people on python-dev have said that the file.read() idiom of returning '' when it's done should be replaced by a true iterator, i.e. using StopIteration. (I don't know the details of exactly how things would change, but I suspect this is something that will happen in Python 3.0.) STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for Webscripting (like PHP)
Florian Lindner wrote: Hello, I've been using Python a lot for scripting (mainly scripts for server administration / DB access). All these scripts were shell based. Now I'm considering using Python (with mod_python on Apache 2) for a web project, just how I've used PHP in some smaller Projects before (?php print foo ?).. How suitable is Python for these kind of projects? What do think? Does the stdlib offers all basic functions for this kind of requirements? An email I got from Dan Richter. Since he has problems with his news/mail gateway I forward it with his permission for the benefit of others. Florian - - - Python is great for heavy lifting: when most of the work is done behind the scenes and outputting the HTML is relatively trivial. An example would be a program that searches archives or computes derivatives. But PHP is designed for web pages and is quite powerful. If you can reasonably do a job in PHP, you probably should. Web sites written in Python usually involve lots of statements like these: uri = os.environ['HTTP_URI'] print 'htmlheadtitle' + theTitle + '/title/head' print '''bodydiv h1The answer to your question/h1 pAfter lots of computing, here's what we discovered./p''' And so on. As you can see, PHP allows you to embed HTML much more gracefully, as well do other web-like things such as retrieve URL query string parameters more easily. So PHP is preferable for most web sites. Depending on what you want to do, you might also consider Perl and Java Servlets. - - - -- http://mail.python.org/mailman/listinfo/python-list
Re: stdin - stdout
max(01)* wrote: i was wondering, what's the simplest way to echo the standard input to the standard output, with no modification. import sys for line in iter(sys.stdin.readline, ''): sys.stdout.write(line) Note that this uses the second form of iter(), which calls its first argument repeatedly until it returns the sentinel value (its second argument). STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: determine variable type
[EMAIL PROTECTED] wrote: trying to determine a variable type, specifically that a variable is an integer. i tried using type(var) but that only seemed to produce a response in the command line. You mean that if you do type(var) at the Python prompt, it gives you a reply, but if you have a line with just that in a script, it doesn't? That has nothing to do with type checks. All Python expressions in Python work like that. In interactive use, unused results are echoed to the screen, but in scripts, they are not. How would you expect the echoed value to be useful in your program? In a script, you need to take care of the output of an expression to get any use from it. A standalone expression on a line of its own is legal Python code, but the result is thrown away... E.g. var = 6 type(var) # Works, but meaningless, noone will know what happened print type(var) # Like the interactive use (more or less) var_type = type(var) # Now you have a variable containing the result # of the expression. You can use that later if type(var) == int: # You can use the result in another construct... print %i is an integer! % var But don't worry so much about type checking. That's typically not so important in Python as is is in most other languages, in fact, if you try to handle types too strictly in Python, you are throwing away a lot of the benefits of Python's dynamic features. Perhaps your code is useful with other types than integers, such as the new decimal type or some upcoming money type. That typecheck might just make it impossible to use your code in some completely meaningful way. If you just did nothing, your code would probably throw an exception if 'var' had a type that didn't make sense, and handling that exception is probably not more difficult than to handle whatever action you planned to take if var wasn't an int... Python is much stricter in its type handling than e.g. C++, so don't worry so much. Trying to add a string to an int etc, will raise a sensible exception. It won't lead to any program crash or give any bizarre result to your calculations. If you're sanitizing user input, that's a good thing of course, but then the safe thing would be to read strings (e.g. via raw_input) and then inspect the string before you evaluate it or cast it to something else. Actually, int() does this pretty well, so you could just do: .while 1: # Loop until broken out of... .response = raw_input('Number please: ') .try: .var = int(response) .break .except ValueError: .print response, 'isn't a number!' -- http://mail.python.org/mailman/listinfo/python-list
Re: Some questions
Thomas Ganss wrote: My blind guess would have been that Tkinter was *not* the GUI of choice for *J*ython. With Jython you'd probably use Swing or SWT. It's certainly less coding to get something working in Jython/Swing than with Java/Swing, but I suspect that there is a cost in runtime performance which might be a problem in some cases. -- http://mail.python.org/mailman/listinfo/python-list
Re: certificate-based authentication (Martin v. Löwis)
The standard xmlrpclib should work fine. You need to inherit from the SafeTransport class, overriding get_host_info to return the x509_info. You then pass an instance of your transport to the ServerProxy. Ok - I have upgraded to the newer version of xmlrpclib that has the 'get_host_info' method. I have created a new class (inherited from the SafeTransport class), and overriden the get_host_info method. So my question now is where does the the x509_info come from? Is that the key/certificate comming back from the server? If so, how do I get that? If not, then where does it come from? You must excuse my ignorance, as this is all fairly new to me, and am still in the learning phase. Thanks Dennis -- http://mail.python.org/mailman/listinfo/python-list
Re: stdin - stdout
gry@ll.mit.edu wrote: import sys for l in sys.stdin: sys.stdout.write(l) This is fine if you don't need the reads and writes of lines to run in lockstep. File iterators read into a buffer, so you'll probably read 4096 bytes from stdin before you ever write a line to stdout. If that's okay, this is a good solution. OTOH, if you want the reads and writes to run in lockstep, you should probably use this idiom: import sys for line in iter(sys.stdin.readline, ''): sys.stdout.write(line) STeVe P.S. You may also be able to get your version working using the -u (unbuffered) option to Python, but I couldn't. -- http://mail.python.org/mailman/listinfo/python-list
Idempotent XML processing
Hello all, In my current project, I am working with XML data in a protocol that has checksum/signature verification of a portion of the document. There is an envelope with a header element, containing signature data; following the header is a body. The signatures are computed as cryptographic checksums of the entire Body element, including start and end tags, exactly as it appears in the data transmission. Therefore, I need to extract the entire text of an element of an XML document. I have a function that scans an XML string and does this, but it seems like a rather clumsy way to accomplish this task. I've been playing with xml.dom.minidom and its toxml() method, but to no avail - the server sends me XML with empty elements as full open/close tags, but toxml() serializes them to the XML empty element (Element/), so the checksum winds up not matching. Is there some parsing mechanism (using PyXML or any other freely usable 3rd party library is an option) that will allow me to accomplish this? Or am I best off sticking with my little string scanning function? TIA, Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: __del__ pattern?
BranoZ wrote: [EMAIL PROTECTED] wrote: For a reasonably portable solution, leave the lock file open. On most systems, you cannot delete an open file,.. On most UNIXes, you can delete an open file. Even flock-ed. This is BTW also an hack around flock. Yes, sorry; my bad. Use file that is writeable by A and B in a directory that is writeable only by root. Is that portable? What's the sequence the program should try? -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
sequence slicing documentation
In trying to work out what's different between the start, stop and step of slice.indices() and the start, stop and step of sequence slicing[1] I found that some of the list slicing documentation[2] is vague. I'd like to submit a documentation fix, but I want to make sure I have it right. Here's what points (3) and (5) of the Sequence Types documentation say now: (3) If i or j is negative, the index is relative to the end of the string: len(s) + i or len(s) + j is substituted. But note that -0 is still 0. ... (5) The slice of s from i to j with step k is defined as the sequence of items with index x = i + n*k such that $0 \leq n \frac{j-i}{k}$. In other words, the indices are i, i+k, i+2*k, i+3*k and so on, stopping when j is reached (but never including j). If i or j is greater than len(s), use len(s). If i or j are omitted then they become ``end'' values (which end depends on the sign of k). Note, k cannot be zero. I'd like to replace that second-to-last sentence in point (5) with the vague ``end'' description with something more explicit. I'd like it to read something like: If k is positive and i or j is omitted, they will be replaced with 0 and len(s) respectively. If k is negative and i or j is omitted, they will be replaced with -1 and -len(s)-1 respectively. Note that these replacements happen before the rule from point (3) is applied. I'd also like to put an example with point (5) to show this behavior in action. Something like: So for example:: seq = 'abcde' len(seq) 5 'edc' == seq[:1:-1] == seq[-1:1:-1] True 'ca' == seq[2::-2] == seq[2:-5-1:-2] True Note however that manually applying the rule from point (3) (adding len(s) to any i or j that is negative) works for i, but does not work for j:: seq[5-1:1:-1] 'edc' seq[2:-1:-2] '' This is because Python sees the -1 in the j position and applies the rule from point (3) again. If a few people could check over my logic here and make sure I'm not completely misguided, I'll post a documentation fix. Thanks, STeVe [1] http://mail.python.org/pipermail/python-list/2005-August/293963.html [2] http://docs.python.org/lib/typesseq.html -- http://mail.python.org/mailman/listinfo/python-list
Re: while c = f.read(1)
In article [EMAIL PROTECTED], Antoon Pardon [EMAIL PROTECTED] wrote: ... But '', {}, [] and () are not nothing. They are empty containers. Oh come on, empty is all about nothing. And 0 is not nothing either it is a number. Suppose I have a variable that is either None if I'm not registered and a registration number if I am. In this case 0 should be treated as any other number. Such possibilities, make me shy away from just using 'nothing' as false and writing out my conditionals more explicitly. Sure, if your function's type is None | int, then certainly you must explicitly check for None. That is not the case with fileobject read(), nor with many functions in Python that reasonably and ideally return a value of a type that may meaningfully test false. In this case, comparison (==) with the false value ('') is silly. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Idempotent XML processing
In my current project, I am working with XML data in a protocol that has checksum/signature verification of a portion of the document. ... the server sends me XML with empty elements as full open/close tags, but toxml() serializes them to the XML empty element (Element/), so the checksum winds up not matching. (This is a horrible response to your question, so I apologize in advance.) Does it even make sense to use a checksum to verify XML, since there are basically[1] infinite ways to validly write equivalent XML data? I would think the only way that a checksum would be a viable way to verify a document is if you had some sort of standard normalized format, and made sure the data was normalized both before you computed and before you calculated the checksum. That way, you would be sure that, for instance, all insignificant whitespace was removed and all empty elements were represented uniformly. Again, I'm sorry because I didn't provide any real useful information, I just tried to poke holes in your current project. Will. [1] Unless all of your whitespace is significant -- http://mail.python.org/mailman/listinfo/python-list
Re: __del__ pattern?
Bryan Olson wrote: Use file that is writeable by A and B in a directory that is writeable only by root. Is that portable? I have the feeling that you are asking if it works on Windows. No idea! I have only user experience with Windows. On UNIX it is as portable as 'flock', which means all modern Unices (be careful about NFS). What's the sequence the program should try? 1. open a file, which name was previously agreed on (like /var/tmp/prog-name-user-name) If it fails, report error and exit. System error or somebody has created unaccessible file by the same name. 2. Try to aquire a flock on the descriptor from step 1. If it fails, some running process already has the lock, exit 3. lock will be released and lockfile closed automaticaly by OS on process exit. import sys, fcntl try: lockfile=open('/var/tmp/test1', 'w') fcntl.flock(lockfile.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) except IOError: print sys.exc_info()[1] sys.exit(-1) You can flock any open file, no matter if it is read/write/append. BranoZ -- http://mail.python.org/mailman/listinfo/python-list
Re: global interpreter lock
In article [EMAIL PROTECTED], Bryan Olson [EMAIL PROTECTED] wrote: km wrote: Hi all, is true parallelism possible in python ? or atleast in the coming versions ? is global interpreter lock a bane in this context ? No; maybe; and currently, not usually. On a uniprocessor system, the GIL is no problem. On multi- processor/core systems, it's a big loser. I rather suspect it's a bigger winner there. Someone who needs to execute Python instructions in parallel is out of luck, of course, but that has to be a small crowd. I would have to assume that in most applications that need the kind of computational support that implies, are doing most of the actual computation in C, in functions that run with the lock released. Rrunnable threads is 1 interpreter, plus N allow threads C functions, where N is whatever the OS will bear. Meanwhile, the interpreter's serial concurrency limits the damage. The unfortunate reality is that concurrency is a bane, so to speak -- programming for concurrency takes skill and discipline and a supportive environment, and Python's interpreter provides a cheap and moderately effective support that compensates for most programmers' unrealistic assessment of their skill and discipline. Not that you can't go wrong, but the chances you'll get nailed for it are greatly reduced - especially in an SMP environment. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for Webscripting (like PHP)
You might want to check out spyce. It uses a server page model (like jsp and php) so you can embed python in html. It has the standard stuff you would need for making a web site (session support, etc) and also contains features like custom tags. http://spyce.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Idempotent XML processing
Michael Ekstrand wrote: Hello all, In my current project, I am working with XML data in a protocol that has checksum/signature verification of a portion of the document. There is an envelope with a header element, containing signature data; following the header is a body. The signatures are computed as cryptographic checksums of the entire Body element, including start and end tags, exactly as it appears in the data transmission. Therefore, I need to extract the entire text of an element of an XML document. I have a function that scans an XML string and does this, but it seems like a rather clumsy way to accomplish this task. I've been playing with xml.dom.minidom and its toxml() method, but to no avail - the server sends me XML with empty elements as full open/close tags, but toxml() serializes them to the XML empty element (Element/), so the checksum winds up not matching. Is there some parsing mechanism (using PyXML or any other freely usable 3rd party library is an option) that will allow me to accomplish this? Or am I best off sticking with my little string scanning function? Read up on XML canonicalization (abrreviated as c14n). lxml implements this, also xml.dom.ext.c14n in PyXML. You'll need to canonicalize on both ends before hashing. To paraphrase an Old Master, if you are running a cryptographic hash over a non-canonical XML string representation, then you are living in a state of sin. -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: BeautifulSoup
Steve - Is there a chance you could post a before and after example, so we can see just what you are trying to do instead of talking conceptually all around it and making us guess? If you are just doing some spot translations of specific values in an HTML file, you can probably get away with a simple (but readable) program using pyparsing. -- Paul -- http://mail.python.org/mailman/listinfo/python-list
python classes taught
anyone know of any college/school that is teaching the python language? -- http://mail.python.org/mailman/listinfo/python-list
Re: BeautifulSoup
Here's a pyparsing program that reads my personal web page, and spits out HTML with all of the HREF's reversed. -- Paul (Download pyparsing at http://pyparsing.sourceforge.net.) from pyparsing import Literal, quotedString import urllib LT = Literal() GT = Literal() EQUALS = Literal(=) htmlAnchor = LT + A + HREF + EQUALS + quotedString.setResultsName(href) + GT def convertHREF(s,l,toks): # do HREF conversion here - for demonstration, we will just reverse them print toks.href return A HREF=%s % toks.href[::-1] htmlAnchor.setParseAction( convertHREF ) inputURL = http://www.geocities.com/ptmcg; inputPage = urllib.urlopen(inputURL) inputHTML = inputPage.read() inputPage.close() print htmlAnchor.transformString( inputHTML ) -- http://mail.python.org/mailman/listinfo/python-list
Python 2.1 Bible Source
Hi Everyone! Just started with Python 2 weeks ago and I can't put it down it's to easy and to powerful, I'm sure the goons will be after us for having it soon, Hi Hi. Was wondering if anyone might know where I can find the source code for PYTHON 2.1 BIBLE book. Apparently it was online until the publisher sold the company. I also understand it has been sold a second time since the book was published. Maybe someone has a copy? Thanks. DOUG. -- http://mail.python.org/mailman/listinfo/python-list
Re: Idempotent XML processing
On Aug 19, 2005, at 12:11 PM, Will McCutchen wrote: In my current project, I am working with XML data in a protocol that has checksum/signature verification of a portion of the document. ... the server sends me XML with empty elements as full open/close tags, but toxml() serializes them to the XML empty element (Element/), so the checksum winds up not matching. Does it even make sense to use a checksum to verify XML, since there are basically[1] infinite ways to validly write equivalent XML data? [...] Again, I'm sorry because I didn't provide any real useful information, I just tried to poke holes in your current project. I would agree that this mechanism doesn't make much sense. It certainly doesn't seem to fit well within the conventions most parsing ideologies; I don't know what parsing mechanism the protocol authors had in mind. Unfortunately, I did not write the protocol... I must merely speak it. - Michael -- http://mail.python.org/mailman/listinfo/python-list
ANN: PyDev 0.9.7.99 released
Hi All, PyDev - Python IDE (Python Development Enviroment for Eclipse) version 0.9.7.99 has just been released. Check the homepage (http://pydev.sourceforge.net/) for more details. Details for Release: 0.9.7.99 OK, what's with the strange release version number?... Well, this version undergone lot's of changes, so, PyDev will be waiting on feedback about them... only after that will it become 0.9.8! Major highlights: * PyDev has its first shot at Jython. you should be able to use many things already, meaning: all the common editor features and code completion. * The debugger is working. Others that are new and noteworthy: * Code completion has been improved for supporting wild imports and relative imports better (sometimes it had some problems). * There are hovers for the text and annotations (when you pass the mouse through an error it will show its description). * Block comment (Ctrl+4) now uses the size defined for the print margin. * New block-comment style added (Ctrl+Shift+4). * New icons were created. * wxPython completions now show. * Many other bug-fixes as usual. Note on Java 1.4 support: Currently Java 1.4 is not supported (only java 5.0), altough we will try to add support for java 1.4 before the 1.0 release. Special thanks --- This release would not be possible without help from: OctetString, for the financial support for making jython support possible! Aleks Totic, Scott Schlesier and Vitor Oba for the debugger patches! Eduardo A. Hoff, for the new logo and changes on the site layout! Cheers, Fabio -- Fabio Zadrozny -- Software Developer ESSS - Engineering Simulation and Scientific Software www.esss.com.br PyDev - Python Development Enviroment for Eclipse pydev.sf.net pydev.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
[Jython-users] ANN: PyDev 0.9.7.99 released
Hi All, PyDev - Python IDE (Python Development Enviroment for Eclipse) version 0.9.7.99 has just been released. Check the homepage (http://pydev.sourceforge.net/) for more details. Details for Release: 0.9.7.99 OK, what's with the strange release version number?... Well, this version undergone lot's of changes, so, PyDev will be waiting on feedback about them... only after that will it become 0.9.8! Major highlights: * PyDev has its first shot at Jython. you should be able to use many things already, meaning: all the common editor features and code completion. * The debugger is working. Others that are new and noteworthy: * Code completion has been improved for supporting wild imports and relative imports better (sometimes it had some problems). * There are hovers for the text and annotations (when you pass the mouse through an error it will show its description). * Block comment (Ctrl+4) now uses the size defined for the print margin. * New block-comment style added (Ctrl+Shift+4). * New icons were created. * wxPython completions now show. * Many other bug-fixes as usual. Note on Java 1.4 support: Currently Java 1.4 is not supported (only java 5.0), altough we will try to add support for java 1.4 before the 1.0 release. Special thanks --- This release would not be possible without help from: OctetString, for the financial support for making jython support possible! Aleks Totic, Scott Schlesier and Vitor Oba for the debugger patches! Eduardo A. Hoff, for the new logo and changes on the site layout! Cheers, Fabio -- Fabio Zadrozny -- Software Developer ESSS - Engineering Simulation and Scientific Software www.esss.com.br PyDev - Python Development Enviroment for Eclipse pydev.sf.net pydev.blogspot.com --- SF.Net email is Sponsored by the Better Software Conference EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile Plan-Driven Development * Managing Projects Teams * Testing QA Security * Process Improvement Measurement * http://www.sqe.com/bsce5sf ___ Jython-users mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jython-users -- http://mail.python.org/mailman/listinfo/python-list
A script to run all of my project's pyunit tests
Hey All, I am trying to write a script that runs all of my pyunit tests for me. Ideally, I would like to be able to drop a new module into my project's test subdirectory, and the testing script will pick it up automatically. At the moment, I have it working but it is kinda a kludge because every TestCase must provide a function that returns a TestSuite for all of its tests. Here is the basic process and a stripped down version of the script: 1. Locate each `.py' file in my project's test subdirectory. 2. Import the module found in step 1. 3. Get a TestSuite of all of the tests in the module imported in step 2. 4. Add the TestSuite from step 3 to a growing list of suites. 5. Make one granddaddy TestSuite from the list of all those fetched in steps 1 through 4. 6. Create a runner, pass it the uber TestSuite, and run all the tests. My scripts to do these things is as follows: == import os, sys, unittest from glob import glob projHome = os.getenv(PROJ_HOME) sys.path.insert(0, projHome + /tests) tests = [] for file in glob(projHome + /tests/*.py): start = file.rfind(/) + 1 end = file.rfind(.) moduleName = file[start:end] module = __import__(moduleName) tests.append(module.getTestSuite()) #---^ # The part that I'm not happy with. allTests = unittest.TestSuite(tests) runner = unittest.TextTestRunner(verbosity=2) runner.run(allTests) == With this setup, every module has to have a `getTestSuite' function that returns a TestSuite for the module. This is suboptimal and annoying. The function looks like this is all of my TestCase subclasses: == class MyTestCase(unittest.TestCase): pass def getTestSuite(): return suite if __name__ == __main__: unittest.main() else: global suite suite = unittest.makeSuite(MyTestCase, 'test') == The problem is that I can't figure out how to do something similar to the TestCases' `unittest.makeSuite(MyTestCase, 'test')' in the script that I'm using to run all of the tests. If anyone has any help or suggestions, I would really appreciate it. -- Regards, Travis Spencer -- http://mail.python.org/mailman/listinfo/python-list