Next meeting: Tuesday 11th August
The next meeting of the Melbourne Python Users Group will be on Tuesday the 11th of August starting at 6:30pm. We'll be meeting at Horse Bazaar again but this time we'll have use of their projector. We'll have time for several short presentations or lightning talks. Meeting details, location and talks list are at: http://wiki.python.org/moin/MelbournePUG If you've seen something cool or are doing something cool then we'd like you to tell everyone about it! Presentations could be 5 minutes or up to 15 minutes if you'd like to ramble for a bit longer. I'll be getting up to talk a bit about my experiences playing with IronPython - what's cool and what's downright odd :) If you've got an idea for a talk just add it to the wiki page. Richard -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
[ANN]: pyxser-1.1r --- python xml serialization
-BEGIN PGP SIGNED MESSAGE- Hash: SHA512 Hello, I'm pleased to announce pyxser-1.1r, a Python-Object to XML serializer and deserializer. This package it's completly written in C and licensed under LGPLv3. The tested Python versions are 2.5.X and 2.7.X. * home page: http://coder.cl/software/pyxser * hosted at: http://sourceforge.net/projects/pyxser/ The current ChangeLog is as follows: - -8--8--8--8- 1.1r (2009.05.09): Daniel Molina Wegener d...@coder.cl * Removed bugs concerning XML schema declaration for output documents. * Removed bugs concerning XML schema design for C14N serialization. * Removed exc argument from C14N serialization functions, because they have no sense. * Code cleanup with function arguments (C code). * All changes seems to be transparent for previous versions. - -8--8--8--8- Also, I need a little bit of feedback. I want it to be able to serialize files and buffers: I've planned to allow the user to have three options: ignore files, serialize them in base64 encoding and just put the file name as string. But my question concerns how the files and buffers are deserialized: I must allow the user to dump the files on a directory, put the complete file on a buffer object, or just extract the base64 encoded block? Best regards and thanks in advance... - -- .O. | Daniel Molina Wegener | FreeBSD Linux ..O | dmw [at] coder [dot] cl | Open Standards OOO | http://coder.cl/| FOSS Developer -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (FreeBSD) iQIcBAEBCgAGBQJKbmrBAAoJEHxqfq6Y4O5NUM4P/2+wdZDWkVWrfbg3DA68n4C7 Le4BTCHF9bZBahDXqIq46f2jT6hfNuh+y7nrk3q5V7MchJdHRZU+Sft99mVaBfrT W7QCMg1JDs8ibOCTy+WN/j2L/gdjFWaez4jTfXU9qz6yBYd1drm6nRG1E36uiaF8 dLYDJgb+2Iykg3cYXnqYSKZqzlQxsmgun6+XlE1C0oWUknkSGqUdk4dPORXhbGAO H+EJLClKmM9Xbg2B9XaGhwHmp73bKgDRj8+2RPN8oQXjNgawwo9gUTsGVwVPyOuI UmbJkKSjkDcxwfLP/nGvIDchdZ+4hCDtFpuEuOUHuk52ga3K5WZXtuYaPU6kup+n CgQZDMNA9qbKsplMuIkakTE3ahAfCCttBHj4PQRshKQkPzHmVxHlo9N0F3jJumI8 1YO17QjBiSmTjAy0XUTicXQd6xC5iF9XnrIMewNaAOt1EFK7Kj+P/Hckoqc/QQtL ANX/wD3YfoyZJ+2a8a8t2Wz2xINZRfUvlyjv7lmogbjHcyeO4XcRoUGmSqrwYzE/ /dlviErz73eTkYdieQgXePKUeV8MvIscCYipfWFsHdUosjQBkIiecrCsI9vDwhNe AZREgRDD9Eh5CWIWEwRfesUy6Kw30xbY+Bk9nSTryWTKB5KAhb3eLUx3h55XG3Bd R9ukduTENnYcYFYRl/iP =GeVp -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Python-URL! - weekly Python news and links (Jul 28)
QOTW: But there's another principle at work here that's less well known, and that was first articulated to me by Robert Dewar: You can remove linear factors by profiling, but it's much harder to undo bad algorithmic decisions. In particular, whether a program runs in O(n) or O(n^2) sometimes depends on decisions that have to be frozen fairly early in the design. - Andrew Koenig Comparing the performance of the same algorithm using many compilers: CPython, psyco, Cython, ShedSkin, Unladen Swallow, Java, C and D: http://groups.google.com/group/comp.lang.python/browse_thread/thread/8d793c46903cc0b6/ MRAB has written a new implementation of re module with many new features, and he's looking for feedback: http://groups.google.com/group/comp.lang.python/browse_thread/thread/16c139b0a52ab023/ Importing two modules with the same name from different directories: http://groups.google.com/group/comp.lang.python/browse_thread/thread/3cb83a30e1b2c202/ Cleanly exiting an application, even if it gets killed by a signal: http://groups.google.com/group/comp.lang.python/browse_thread/thread/d60b8e0d93aeaaf9/ How can a child thread notify a parent thread of its status? http://groups.google.com/group/comp.lang.python/browse_thread/thread/d1d7f55716aacedc/ How to attach a docstring to global constants/variables? http://groups.google.com/group/comp.lang.python/browse_thread/thread/ac54186ad873036a/ In Python -unlike other languages- it does not make sense to treat numbers (scalars) as vectors of length 1: http://groups.google.com/group/comp.lang.python/browse_thread/thread/3ef498c906bd7e2d/ isinstance may take a tuple of types as its second argument: why a tuple, and not a list, or a set? http://mail.python.org/pipermail/python-list/2009-July/721205.html How to overcome the normal 2GB allocation limit of Windows XP, 32bits: http://groups.google.com/group/comp.lang.python/browse_thread/thread/59851df6e54f9ef0/ Distinguishing active generators from exhausted ones: http://groups.google.com/group/comp.lang.python/browse_thread/thread/9ff179e8cb5e9bc/ Peter Otten must be, undoubtedly, Sherlock Holmes reincarnated: http://groups.google.com/group/comp.lang.python/browse_thread/thread/838177c8a37d2b7c/ And Piet van Oostrum is not much behind him: http://groups.google.com/group/comp.lang.python/browse_thread/thread/d1f8627413cd3c4e/ 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 Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish the efforts of Python enthusiasts: http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the Planet sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes podcasts ... to help people learn Python ... Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ 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/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.orggroup=gmane.comp.python.develsort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few
[ANN] Pyjamas 0.6pre2 Python Web Widget Set and Javascript Compiler
http://pyjs.org this is a pre-release announcement, 0.6pre2, of the pyjamas widget set and python-to-javascript compiler. there are over 110 entries in the CHANGELOG since the last stable release, 0.5p1, and so it was deemed sensible to invite people to test this version before its next stable release, 0.6. pyjamas, being a port of GWT to python, comprises four main components: * a stand-alone python-to-javascript compiler * a desktop-based wrapper around python-xpcom or pywebkitgtk * a browser DOM model wrapper interface * a widget set similar to pygtk2 / pyqt4, based on DOM manipulation significantly in the 0.6 series, pyjamas-desktop has been incorporated into the build: python Hello.py will start a stand-alone app (just as you would with pygtk2 or pyqt4) and pyjsbuild Hello will compile the javascript version(s). the combination means that pyjamas can run python applications - unmodified - in all major web browsers, or on the desktop (using gecko or webkit) in a similar fashion to adobe AIR. in the javascript version: somewhere along the line, a massive performance hit was introduced by accident. this has now been fixed. however, random desperate attempts to improve performance, before the mistake was corrected, mean that the pyjamas 0.6pre2 python-to-javascript compiler produces code that is stunningly quick. also in the 0.6pre2 release, strict python options have now been introduced, so that developers can expect much more support for the standard python 2.5 / 2.6 language semantics. the -O option disables many of these features, bringing a quite significant speed increase, by sacrificing python compatibility. that's just the way it has to be. downloads can be found by following the links from http://pyjs.org - sourceforge, code.google.com, pypi, all the usual places. lastly - thank you to everyone who's helped with pyjamas: bernd, bernd, jurgen, christian, kees, ondrej and many more, and especially thank you to the people who helped out by pointing out bugs in the 0.6pre1 release, please keep it up! l. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: Error in compiling Python on OS X
On Jul 26, 3:46 pm, Diez B. Roggisch de...@nospam.web.de wrote: Kevin schrieb: I am trying to compile Python 2.6.2 on Mac OS X 10.5.7. I have Xcode 3.1.3 installed. The error I got is below. $ ./configure --prefix=/Users/me/python Use a framework-build. checking for --with-universal-archs... 32-bit checking MACHDEP... darwin checking EXTRAPLATDIR... $(PLATMACDIRS) checking machine type as reported by uname -m... i386 checking for --without-gcc... no checking for gcc... gcc checking for C compiler default output file name... configure: error: C compiler cannot create executables See `config.log' for more details. Please send any ideas. What happens if you write a simple test.c like this: int main() { return 0; } and compile it with gcc on the commandline? There must be a file called a.out afterwards. diez I have solved my problem. I think something was wrong with my compiler. After I installed Xcode again, I was able to compile with no problems. -- http://mail.python.org/mailman/listinfo/python-list
Re: Download the head of a large file?
Dennis Lee Bieber wrote: On Mon, 27 Jul 2009 13:38:25 -0700 (PDT), erikcw erikwickst...@gmail.com declaimed the following in gmane.comp.python.general: Something like the Python equivalent of curl http://url.com/file.xml | head -c 2048 Presuming that | is a shell pipe operation, then doesn't that command line use curl to download the entire file, and head to display just the first 2k? No, the entire file is not downloaded. My understanding of why this is (which could be wrong) is that the output of curl is piped to head, and once head gets the first 2k it closes the pipe. Then, when curl tries to write to the pipe again, it gets sent the SIGPIPE signal at which point it exits. Cheers, Ben -- http://mail.python.org/mailman/listinfo/python-list
Determining __name__ from the code that called a function
Hi, In ToscaWidgets 2 experimental, when defining resources you often do something like this: CSSLink(modname=__name__, filename='static/mycss.css') Now, what I'd like to do is make the modname=__name__ optional, to make code more concise. I figure there must be some way (using inspect or something) to determine what __name__ would be in the code that just called my function. Couldn't immediately see how to do this - any suggestions? Thanks, Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: What is file.encoding convention?
En Thu, 23 Jul 2009 21:49:26 -0300, Naoki INADA songofaca...@gmail.com escribió: The encoding that this file uses. When Unicode strings are written to a file, they will be converted to byte strings using this encoding. In addition, when the file is connected to a terminal, the attribute gives the encoding that the terminal is likely to use I feel this doc means file object with encoding attribute encodes unicode regardless it is tty or not and sys.stdout/stderr defies convention. The 'encoding' file attribute is very confusing and mostly unsupported (or there is a bug in the documentation, at least in Python 2.x). See http://bugs.python.org/issue4947 -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: exceptions.TypeError an integer is required
En Mon, 27 Jul 2009 12:44:40 -0300, jakecjacobson jakecjacob...@gmail.com escribió: You are quite correct in your statements. My goal was not to make great code but something that I could quickly test. My assumption was that the httplib.HTTPSConnection() would do the cast to int for me. As soon as I cast it to an int, I was able to get past that issue. A few remarks that may help learning the language: Note that Python is a strongly typed (and dynamic) language. All objects have a defined type: 443 is not the same thing as 443, and 2 + 2 raises a TypeError. If a function expects an integer, you must provide an integer (or something that at least acts as an integer; a string isn't integer-alike at all from Python's POV) Also, you don't cast an object into another: the expression int(443) is a constructor, and it returns a new object (an integer) based upon its argument. (so it's quite different from, say, casting short to unsigned short in C, that only changes the way the compiler treats the same bytes in memory). -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
WSDL and XML generation
Hi all Newbie in Python, i am looking for some pointers (or better existing modules) to do the followings: - generate (correct) XML messages from a WSDL file - make some modifications inside XML messages *before* sending them to the server hosting the Web services (described by previously mentionned WSDL file) - parse the answer. Some ideas ? Thanks in advance Stephane -- http://mail.python.org/mailman/listinfo/python-list
Re: Testoob: How do you use testoob.collector_from_globals / collector_from_modules?
Hi Harry, I forwarded this to the Testoob list at http://groups.google.com/group/testoob Ori. On Jul 27, 4:12 pm, Harry Ebbers neme...@gmail.com wrote: Hi, For a project I'm creating unittests using testoob. When all tests are in a single file there is no problem if __name__ == '__main__': testoob.main() does the trick as usual. But for a number of python-applications they have asked me to group unittests in different files, based on common functionality (e.g. GUI, main-application, etcetera). Ican get it to work by importing all unittestclasses in the following way and than use the normal if __name__ == '__main__' construction (from GUI import GUItests from APP import APPtests if __name__ == '__main__': testoob.main()) But looking at the future I would like to use testsuites. On the internet I found the functions testoob.collector_from_globals and collector_from_modules which one can use to 'easily' create testsuites which can be used with testoob. But no examples on how to use them can be found. Can anybody supply me with a working example? TIA Harry Ebbers -- http://mail.python.org/mailman/listinfo/python-list
Re: RSA cryptography between Python and Java
Rob Knop wrote: I've created an RSA key in Java. I have exported the public key by making it into a X509EncodedKeySpec and spitting out the result of getEncoded(). I want to use this public key to encode something in python that I will send to Java, and then decode in Java with the corresponding private key. Are there any python libraries that will take a public key in this format and do RSA encoding on it? M2Crypto will let you do this: http://chandlerproject.org/bin/view/Projects/MeTooCrypto If you have access to the raw key data (instead of having it encoded in a X509 certificate), then you can also use PyCrypto, which does require setting up OpenSSL first: http://www.dlitz.net/software/pycrypto/ -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jul 28 2009) Python/Zope Consulting and Support ...http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ ::: Try our new mxODBC.Connect Python Database Interface for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ -- http://mail.python.org/mailman/listinfo/python-list
Re: bad certificate error
jakecjacobson jakecjacob...@gmail.com wrote: I am getting the following error when doing a post to REST API, Enter PEM pass phrase: Traceback (most recent call last): File ./ices_catalog_feeder.py, line 193, in ? main(sys.argv[1]) File ./ices_catalog_feeder.py, line 60, in main post2Catalog(catalog_host, catalog_port, catalog_path, os.path.join (input_dir, file), collection_name, key_file, cert_file) File ./ices_catalog_feeder.py, line 125, in post2Catalog connection.request('POST', path, parameters, head) File /usr/lib/python2.4/httplib.py, line 810, in request self._send_request(method, url, body, headers) File /usr/lib/python2.4/httplib.py, line 833, in _send_request self.endheaders() File /usr/lib/python2.4/httplib.py, line 804, in endheaders self._send_output() File /usr/lib/python2.4/httplib.py, line 685, in _send_output self.send(msg) File /usr/lib/python2.4/httplib.py, line 652, in send self.connect() File /usr/lib/python2.4/httplib.py, line 1079, in connect ssl = socket.ssl(sock, self.key_file, self.cert_file) File /usr/lib/python2.4/socket.py, line 74, in ssl return _realssl(sock, keyfile, certfile) socket.sslerror: (1, 'error:14094412:SSL routines:SSL3_READ_BYTES:sslv3 alert bad certificate') My code where this error occurs is: head = {Content-Type : application/x-www-form-urlencoded, Accept : text/plain} parameters = urlencode({collection : collection, entryxml : open (file,'r').read()}) print Sending the file to: + host try: try: # Default port is 443. # key_file is the name of a PEM formatted file that contains your private key. # cert_file is a PEM formatted certificate chain file. connection = httplib.HTTPSConnection(host, int(port), key_file, cert_file) connection.request('POST', path, parameters, head) response = connection.getresponse() print response.status, response.reason except httplib.error, (value,message): print value + ':' + message finally: connection.close() I was wondering if this is due to the server having a invalid server cert? I'd say judging from the traceback you messed up key_file or cert_file somehow. Try using the openssl binary on them (read the man page to see how!) to check them out. If I go to this server in my browser, I get a This server tried to identify itself with invalid information. Is there a way to ignore this issue with Python? Can I setup a trust store and add this server to the trust store? Invalid how? Self signed certificate? Domain mismatch? Expired certificate? -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Determining __name__ from the code that called a function
En Tue, 28 Jul 2009 03:21:10 -0300, Paul Johnston paul@gmail.com escribió: In ToscaWidgets 2 experimental, when defining resources you often do something like this: CSSLink(modname=__name__, filename='static/mycss.css') Now, what I'd like to do is make the modname=__name__ optional, to make code more concise. I figure there must be some way (using inspect or something) to determine what __name__ would be in the code that just called my function. Couldn't immediately see how to do this - any suggestions? In CPython, you may use sys._getframe(1).f_globals['__name__'] but I don't know how portable is that across Python implementations. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: ioctl on socket
Gabriel Genellina wrote: En Mon, 27 Jul 2009 16:35:51 -0300, jacopo mondi mo...@cs.unibo.it escribió: Is there a reason why there is no ioctl interface for socket either then for windows platform? It's technical issues or what else?? I don't completely understand your question. On Windows, you can use socket.ioctl with sockets, and DeviceIoControl (from the pywin32 package) with other files. On Linux, you have fcntl.ioctl that works with any kind of file. Ok, thanks a lot, my question was because I didn't know about fcntl.ioct, I thought that ioctl wrapping was implemented inside socketmodule.c as 'bind', 'connect', 'accept' etc. are, and I was disoriented because no documentation for socket usage on Linux nor the code have references about ioctl, except for windows. I hope the reason why you didn't completely understood my question is not my english, if it be so I'm sorry and I ask anyone to correct me, it's the only way to improve ;) thanks a lot jacopo -- http://mail.python.org/mailman/listinfo/python-list
Re: where do I put resources (images, audio files) when I wrote Python program?
Piotrek wrote: that? I think about puting these files in /usr/share/myprogram and then reading it the normal way (so the path /usr/share/myprogram would be just hardwired in my program). Is it the way one usually does it in Python program or is there any more sofisticated way? Just keep them in your sources, and create an empty __init__.py file in the images directory. Then install setuptools and use the pkg_resources module. It will work even if your application is installed as an egg through easy_install, possibly zipped. To open a resource file: f = pkg_resources.resource_stream('path.to.package', 'resource.png') f.read() Return a readable file-like object for the specified resource; it may be an actual file, a StringIO, or some similar object. The stream is in binary mode, in the sense that whatever bytes are in the resource will be read as-is. -- http://mail.python.org/mailman/listinfo/python-list
The longest word
Newbie hello onwards to the .py manual asks meantime how the longest word gets determined? First word, ok 'a aa aaa aa'[:'a aa aaa aa'.find(' ',1,10)] 'a' rfind is another subset 'a aa aaa aa'[:'a aa aaa aa'.rfind(' ',1,10)] 'a aa aaa' One row should be able. It's a direct word 'a aa aaa...' and can be a variable, it's no big deal it occurs twice still naturally easier if also occured just once. Sincere thanks regards Niklas -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
On Monday 27 July 2009 16:49:25 Aahz wrote: In article mailman.3765.1248685391.8015.python-l...@python.org, Hendrik van Rooyen hend...@microcorp.co.za wrote: On Sunday 26 July 2009 21:26:46 David Robinow wrote: I'm a mediocre programmer. Does this mean I should switch to PHP? I have searched, but I can find nothing about this mediocre language. Could you tell us more? :-P (For anyone who is confused by Hendrik's humor, he is saying that David was referring to a programming language named mediocre. English grammar is confusing!) This is true - I intended, when I started the post, to make a crack about how he knew that he was mediocre - If there were some exam or test that you have to pass or fail to be able to make the claim to mediocrity. I was imagining a sort of devil's rating scale for programmers, that could cause one to say things like: I am studying hard so that I can get my mediocre certificate, and one day I hope to reach hacker rank. And then the similarity to I am a COBOL programmer struck me, and I abandoned the ratings. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: The longest word
On Jul 28, 10:26 am, NiklasRTZ nikla...@gmail.com wrote: Newbie hello onwards to the .py manual asks meantime how the longest word gets determined? First word, ok 'a aa aaa aa'[:'a aa aaa aa'.find(' ',1,10)] Your language is not easy to understand, but I think you want to find the longest word in a string. If this is the input string: txt = a aa aaa aa There are several ways to do it, I'll show a simple one. You can split it into its parts (not having Python a built-in lazy split yet, you can split it all at once). You can do it with the string split method. It produces a list of the words, more or less (but you may have words like gone,, you may have to take care of them too, this requires some code. Once you have a list of words, you have to take the longest. A simple way is to replace each word with a tuple that contains the length of the word and the word itself, then pick the tuple with the highest length value. But Python allows you to do such operation in a faster way: you can use the max() function, it has a key function that allows you to remap on the fly what you mean by max. So you just have to give it a function (reference) that given the word spits its length, such function is len itself. If you instead want to find the position of the longest word the program gets a little longer. Ask if you need something different. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: The longest word
NiklasRTZ wrote: On Jul 28, 5:02 am, Bearophile bearophileh...@lycos.com wrote: On Jul 28, 10:26 am, NiklasRTZ nikla...@gmail.com wrote: Newbie hello onwards to the .py manual asks meantime how the longest word gets determined? First word, ok 'a aa aaa aa'[:'a aa aaa aa'.find(' ',1,10)] Your language is not easy to understand, but I think you want to find the longest word in a string. If this is the input string: txt = a aa aaa aa There are several ways to do it, I'll show a simple one. You can split it into its parts (not having Python a built-in lazy split yet, you can split it all at once). You can do it with the string split method. It produces a list of the words, more or less (but you may have words like gone,, you may have to take care of them too, this requires some code. Once you have a list of words, you have to take the longest. A simple way is to replace each word with a tuple that contains the length of the word and the word itself, then pick the tuple with the highest length value. But Python allows you to do such operation in a faster way: you can use the max() function, it has a key function that allows you to remap on the fly what you mean by max. So you just have to give it a function (reference) that given the word spits its length, such function is len itself. If you instead want to find the position of the longest word the program gets a little longer. Ask if you need something different. Bye, bearophile Thank you. This seems to work: sorted(a AAA aa a sdfsdfsdfsdf vv.split(' '),lambda a,b: len(a)- len(b))[-1] 'sdfsdfsdfsdf' To spell out bearophile's more efficient suggestion: max(a AAA aa a sdfsdfsdfsdf vv.split(), key=len) 'sdfsdfsdfsdf' -- http://mail.python.org/mailman/listinfo/python-list
Re: bad certificate error
On Jul 28, 3:29 am, Nick Craig-Wood n...@craig-wood.com wrote: jakecjacobson jakecjacob...@gmail.com wrote: I am getting the following error when doing a post to REST API, Enter PEM pass phrase: Traceback (most recent call last): File ./ices_catalog_feeder.py, line 193, in ? main(sys.argv[1]) File ./ices_catalog_feeder.py, line 60, in main post2Catalog(catalog_host, catalog_port, catalog_path, os.path.join (input_dir, file), collection_name, key_file, cert_file) File ./ices_catalog_feeder.py, line 125, in post2Catalog connection.request('POST', path, parameters, head) File /usr/lib/python2.4/httplib.py, line 810, in request self._send_request(method, url, body, headers) File /usr/lib/python2.4/httplib.py, line 833, in _send_request self.endheaders() File /usr/lib/python2.4/httplib.py, line 804, in endheaders self._send_output() File /usr/lib/python2.4/httplib.py, line 685, in _send_output self.send(msg) File /usr/lib/python2.4/httplib.py, line 652, in send self.connect() File /usr/lib/python2.4/httplib.py, line 1079, in connect ssl = socket.ssl(sock, self.key_file, self.cert_file) File /usr/lib/python2.4/socket.py, line 74, in ssl return _realssl(sock, keyfile, certfile) socket.sslerror: (1, 'error:14094412:SSL routines:SSL3_READ_BYTES:sslv3 alert bad certificate') My code where this error occurs is: head = {Content-Type : application/x-www-form-urlencoded, Accept : text/plain} parameters = urlencode({collection : collection, entryxml : open (file,'r').read()}) print Sending the file to: + host try: try: # Default port is 443. # key_file is the name of a PEM formatted file that contains your private key. # cert_file is a PEM formatted certificate chain file. connection = httplib.HTTPSConnection(host, int(port), key_file, cert_file) connection.request('POST', path, parameters, head) response = connection.getresponse() print response.status, response.reason except httplib.error, (value,message): print value + ':' + message finally: connection.close() I was wondering if this is due to the server having a invalid server cert? I'd say judging from the traceback you messed up key_file or cert_file somehow. Try using the openssl binary on them (read the man page to see how!) to check them out. If I go to this server in my browser, I get a This server tried to identify itself with invalid information. Is there a way to ignore this issue with Python? Can I setup a trust store and add this server to the trust store? Invalid how? Self signed certificate? Domain mismatch? Expired certificate? -- Nick Craig-Wood n...@craig-wood.com --http://www.craig-wood.com/nick Nick, Thanks for the help on this. I will check my steps on openssl again and see if I messed up. What I tried to do was: 1. Save my PKI cert to disk. It was saved as a P12 file 2. Use openssl to convert it to the needed .pem file type 3. Saved the CA that my cert was signed by as a .crt file These are the 2 files that I was using for key_file and * cert_file - CA * key_file - my PKI cert converted to a .pem file Invalid how? Self signed certificate? Domain mismatch? Expired certificate? It is a server name mismatch. For everyone that wants to discuss why we shouldn't do this, great but I can't change the fact that I need to do this. I can't use http or even get a correct cert at this time. This is a quick a dirty project to demonstrate capability. I need something more than slide show briefs. -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: where do I put resources (images, audio files) when I wrote Python program?
Gabriel Genellina wrote: For those read-only resources I'd use pkgutil.get_data (instead of manually parsing __file__): http://docs.python.org/library/pkgutil.html#pkgutil.get_data It's easier to manage when someone later decide to install the package as an egg file, or distribute it using py2exe. Quoting the documentation: The function returns a binary string that is the contents of the specified resource. For packages located in the filesystem, which have already been imported, this is the rough equivalent of: d = os.path.dirname(sys.modules[package].__file__) data = open(os.path.join(d, resource), 'rb').read() return data Thanks Gabriel, I hadn't come across get_data() yet. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: ioctl on socket
En Tue, 28 Jul 2009 07:05:43 -0300, jacopo mondi mo...@cs.unibo.it escribió: Gabriel Genellina wrote: En Mon, 27 Jul 2009 16:35:51 -0300, jacopo mondi mo...@cs.unibo.it escribió: Is there a reason why there is no ioctl interface for socket either then for windows platform? It's technical issues or what else?? I don't completely understand your question. On Windows, you can use socket.ioctl with sockets, and DeviceIoControl (from the pywin32 package) with other files. On Linux, you have fcntl.ioctl that works with any kind of file. Ok, thanks a lot, my question was because I didn't know about fcntl.ioct, I thought that ioctl wrapping was implemented inside socketmodule.c as 'bind', 'connect', 'accept' etc. are, and I was disoriented because no documentation for socket usage on Linux nor the code have references about ioctl, except for windows. I see; socket.ioctl should menction fcntl.ioctl; I'll submit a documentation patch. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: The longest word
Piet van Oostrum p...@cs.uu.nl writes: NiklasRTZ nikla...@gmail.com (N) wrote: N Thank you. This seems to work: N sorted(a AAA aa a sdfsdfsdfsdf vv.split(' '),lambda a,b: len(a)- N len(b))[-1] N 'sdfsdfsdfsdf' simpler: sorted(a AAA aa a sdfsdfsdfsdf vv.split(' '), key=len)[-1] There is no need to sort the sequence to obtain the largest element. The max function is designed to do exactly that, and also supports the key argument: max(a AAA aa a sdfsdfsdfsdf vv.split(' '), key=len) 'sdfsdfsdfsdf' -- http://mail.python.org/mailman/listinfo/python-list
Re: I am trying to compile python 2.6.2 on my Mac
On Jul 26, 2009, at 10:37 AM, Chris Rebert wrote: On Sun, Jul 26, 2009 at 1:12 AM, Jessica R Smithjessica.1980.sm...@gmail.com wrote: Hello, I am trying to compile Python 2.6.2 on my Mac which has os/x 10.5.7 I downloaded python 2.6.2 from here: - http://www.python.org/ftp/python/2.6.2/Python-2.6.2.tar.bz2 I unpacked it. I ran these shell commands: - ./configure --prefix=/pt/p - make Near the end of the make output I see this message: . Failed to find the necessary bits to build these modules: . _bsddb gdbm linuxaudiodev . ossaudiodevreadline spwd . sunaudiodev . To find the necessary bits, look in setup.py in detect_modules() for the module's name. I looked in setup.py in detect_modules() It is not clear to me how to proceed. I think that I want the module: readline I doubt I need the other modules like linuxaudiodev, etc. If you have any clues or opinions on how I can build the module readline, please feel free to share. You need to install the GNU Readline library (http://tiswww.case.edu/php/chet/readline/rltop.html), which the module depends on. A better solution would be to configure the modules in question to use the libreadline.dylib library already installed on every Mac OS X computer. You might consider installing Python through MacPorts or Fink instead, as they automate the compilation and installation process and take care of dependencies (such as GNU Readline) for you: http://www.macports.org/ http://www.finkproject.org/ Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list --- See the amazing new SF reel: Invasion of the man eating cucumbers from outer space. On congratulations for a fantastic parody, the producer replies : What parody? Tommy Nordgren tommy.nordg...@comhem.se -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a dream language: sounds like Python to me.
On Jul 27, 10:39 am, David Cournapeau courn...@gmail.com wrote: On Tue, Jul 28, 2009 at 12:28 AM, Dotan Cohendotanco...@gmail.com wrote: It is neither efficient or inefficient: it is just a distribution tool, to deploy python software in a form familiar to most windows users. It does not make it any faster than running the software under a python prompt. As much as I like python for scientific programming, I would say python is pretty far from the stated requirements in the posted blog post. It is difficult to deploy software written with python (much better than the alternatives, though), and it is slow if you can't leverage numpy/scipy (where vectorization does not apply). It remains to be seen whether it will be true in practice, but something like F#, with its integration in VS 2010, seems much closer IMHO. It is compiled, high level language, and backed by the biggest software vendor in the world. The blog post is not looking to distribute his code, but he would like it to be cross platform for his own reasons. VB is not cross platform. I understand his efficient binary as Ansi C partially as a deployment requirement, and independent of cross-platform issues. As a scientist, being able to share my software with colleagues is a non trivial matter. Python does not make this easy today. F# has nothing to do with VB: F# is a ML-language inspired from OCAML, and run on top of the CLR. It can thus leverage the huge .net framework (lack of non numerical API is one of the biggest matlab hindrance, and comparatively big advantage of python + numpy/scipy), and benefits from the much more efficient implementation compared to python (under the currently CPython implementation at least). Some recent F# versions are compatible with mono, making it compatible on most platforms that matter today for research (but of course, you lose the IDE integration outside windows). David- Hide quoted text - - Show quoted text - I wish . . . For comparisons, Mathcad has the symbolic notation appropriate for mathematical communications. I like features of Mathematica and Maple but Mathcad provides for the user to 'stay' with mathematical symbolism longer. I prefer Matlab execution environment. So I develop concepts in Mathcad, prove them in Matlab and then compile to through C where direct performance is required. Maple and Matlab have this type of relation. Matlab, from The Mathworks, has a companion product called Simulink. This allows the user to graphically build ‘algorithms’ in block form. There is a similar Python function. Each of these components would best be served if allowed to exist independently but supported with transparent integration. I would like to develop in a stable user environment - a stable GUI. And then allow efficient algorithms behind the scenes. By separating the functionality of the workspace, the user can be given (or create at will) a GUI that suites her desires and provides for the creativity and productivity she chooses. The functionality under the GUI should then be pluggable. Developers can provide solutions from many directions, compete for varying performance requirements, enhance functional features technology changes, and still not disturb the fragile user interface. Allow the user the comfort of home. Let them keep whatever GUI suits them and provide for their deployment (if any) needs behind the scenes. Ray -- http://mail.python.org/mailman/listinfo/python-list
Re: The longest word
On Jul 28, 7:03 am, Hrvoje Niksic hnik...@xemacs.org wrote: Piet van Oostrum p...@cs.uu.nl writes: NiklasRTZ nikla...@gmail.com (N) wrote: N Thank you. This seems to work: N sorted(a AAA aa a sdfsdfsdfsdf vv.split(' '),lambda a,b: len(a)- N len(b))[-1] N 'sdfsdfsdfsdf' simpler: sorted(a AAA aa a sdfsdfsdfsdf vv.split(' '), key=len)[-1] There is no need to sort the sequence to obtain the largest element. The max function is designed to do exactly that, and also supports the key argument: max(a AAA aa a sdfsdfsdfsdf vv.split(' '), key=len) 'sdfsdfsdfsdf' Sincere thanks for strengthening python's superior flexibility. Same function also works around an exploding index problem returning results for longest word where otherwise a word with whitespace crashes the index: all().search(max(q.split(), key=len)).filter(modified , timeline).filter(published =, True).filter(modified =, bookmark ).order(-modified).fetch(PAGESIZE+1) Line below crashes the index for words with whitespace (unknown researchable, only occurs live, works with development) all().search(q).filter(modified , timeline).filter(published =, True).filter(modified =, bookmark ).order(-modified).fetch (PAGESIZE+1) best regards, Niklas -- http://mail.python.org/mailman/listinfo/python-list
Re: bad certificate error
On Mon, 27 Jul 2009 23:16:39 -0300, Gabriel Genellina wrote: I don't see the point on fixing either the Python script or httplib to accomodate for an invalid server certificate... If it's just for internal testing, I'd use HTTP instead (at least until the certificate is fixed). In real life, sometimes you need to drive with bad brakes on your car, walk down dark alleys in the bad part of town, climb a tree without a safety line, and use a hammer without wearing goggles. We can do all these things. The OP has said that, for whatever reason, he needs to ignore a bad server certificate when connecting to HTTPS. Python is a language where developers are allowed to shoot themselves in the foot, so long as they do so in full knowledge of what they're doing. So, putting aside all the millions of reasons why the OP shouldn't accept an invalid certificate, how can he accept an invalid certificate? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: bad certificate error
jakecjacobson jakecjacob...@gmail.com wrote: If I go to this server in my browser, I get a This server tried to identify itself with invalid information. Is there a way to ignore this issue with Python? Can I setup a trust store and add this server to the trust store? Invalid how? Self signed certificate? Domain mismatch? Expired certificate? For everyone that wants to discuss why we shouldn't do this, great but I can't change the fact that I need to do this. I can't use http or even get a correct cert at this time. This is a quick a dirty project to demonstrate capability. I need something more than slide show briefs. I wasn't making a value judgement - I was trying to help! If you can get a bit more information out of the browser as to why the certificate is invalid it may help your python code. Real certificates cost real money. Usually a correctly set up self-signed certificate is fine for dev stuff. I'm certainly too cheap to by real certificates for dev or internal stuff! -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
index nested lists
hi at all, If I have this list: lista ['ciao', 1, ['mela', 'pera', 'banana'], [1, 2, 3]] if I want enumerate elements...I can see: for parola in lista: print lista[i] i = i + 1 ciao 1 ['mela', 'pera', 'banana'] [1, 2, 3] but, if I want to enumerate elements about nested lists ??, something like: ciao 1 mela pera banana 1 2 3 ...How can I do ?? Alex -- http://mail.python.org/mailman/listinfo/python-list
File and TagPy
Hello, I have question, is it possible to read tag in tagpy module from file stream? For example I have earlier read file: file = open('some.mp3', 'rb') and next get tags from it? Regards, Konrad -- http://mail.python.org/mailman/listinfo/python-list
FTP Offset larger than file.
I am writing a python script that performs an identical function to the 'tail' unix utility, except that it connects to its files over FTP, rather than the local hard disk. I am currently using this python script to generate an increasing 'logfile' of garbage. import time for i in range(1, 2): time.sleep(0.2) print i f = open(data1.log,a) f.write('%s: This logfile is being automatically generated to help Bakes test his python ftptail. \n' % i) f.close() and use this script to actually download it. import time import os.path from ftplib import FTP #Empty the file filename = 'data1.log' file = open(filename, 'w') file.write('') file.close() def handleDownload(block): file.write(block) print ., # Create an instance of the FTP object # Optionally, you could specify username and password: ftp=FTP(host, user, pass) directory = '/temp' ftp.cwd(directory) file = open(filename, 'a') for i in range(1,2): size=os.path.getsize('data1.log') ftp.retrbinary('RETR ' + filename, handleDownload, rest=size) file.close() print ftp.close() Now, my problem is that I get a very strange error. What should be happening is the script gets the size of the local file before downloading all of the external file after that offset. The error I get is: ftplib.error_temp: 451-Restart offset 24576 is too large for file size 22852. 451 Restart offset reset to 0 which tells me that the local file is larger than the external file, by about a kilobyte. Certainly, the local file is indeed that size, so my local script is doing the right things. I do wonder what is going wrong, can anyone enlighten me? -- http://mail.python.org/mailman/listinfo/python-list
Internal Math Library of Numpy
Does Numpy use Python's standard math library when calculating elementary functions such as exp(x) and acos(x)? Also, what is the internal library of Numpy and Python's standard math library? Is it platform independent? -- http://mail.python.org/mailman/listinfo/python-list
RE: index nested lists
hi at all, If I have this list: lista ['ciao', 1, ['mela', 'pera', 'banana'], [1, 2, 3]] if I want enumerate elements...I can see: for parola in lista: print lista[i] i = i + 1 ciao 1 ['mela', 'pera', 'banana'] [1, 2, 3] but, if I want to enumerate elements about nested lists ??, something like: ciao 1 mela pera banana 1 2 3 ...How can I do ?? Alex -- http://mail.python.org/mailman/listinfo/python-list You could do something like this. def printNestedList(lst): if isinstance(lst, list): for element in lst: printNestedList(element) else: print lst myList = ['ciao', 1, ['mela', 'pera', 'banana'], [1, 2, 3]] printNestedList(myList) ciao 1 mela pera banana 1 2 3 Cheers, Drea -- http://mail.python.org/mailman/listinfo/python-list
Re: index nested lists
On 28 Lug, 15:12, Andreas Tawn andreas.t...@ubisoft.com wrote: hi at all, If I have this list: lista ['ciao', 1, ['mela', 'pera', 'banana'], [1, 2, 3]] if I want enumerate elements...I can see: for parola in lista: print lista[i] i = i + 1 ciao 1 ['mela', 'pera', 'banana'] [1, 2, 3] but, if I want to enumerate elements about nested lists ??, something like: ciao 1 mela pera banana 1 2 3 ...How can I do ?? Alex -- http://mail.python.org/mailman/listinfo/python-list You could do something like this. def printNestedList(lst): if isinstance(lst, list): for element in lst: printNestedList(element) else: print lst myList = ['ciao', 1, ['mela', 'pera', 'banana'], [1, 2, 3]] printNestedList(myList) thanks a lot ! Alex -- http://mail.python.org/mailman/listinfo/python-list
python 3 and stringio.seek
Hi list, I'm trying to port a my library to python 3, but I have a problem with a the stringio.seek: the method not accept anymore a value like pos=-6 mode=1, but the old (2.X) version yes... The error: File /home/devel/Py3/lib/python3.0/io.py, line 2031, in seek return self._seek(pos, whence) IOError: Can't do nonzero cur-relative seeks How solve this? Thanks, MIchele -- http://mail.python.org/mailman/listinfo/python-list
Re: Gracefully exiting CLI application
On Mon, 27 Jul 2009 22:35:01 +0200, David wrote: I am writing a command line application, and I need to perform some cleaning on exit even if the process is killed. How can I do that with python? Killed by what means? Ctrl-C sends SIGINT which is converted to a KeyboardInterrupt exception. This can be caught, or if it's allowed to terminate the process, any exit handlers registered via atexit.register() will be used. For other signals, you can install a handler with signal.signal(). This can call sys.exit() or raise an exception (e.g. KeyboardInterrupt). OTOH, if the process is terminated by SIGKILL, there's nothing you can do about it. And although it's possible to trap SIGSEGV, you shouldn't assume that the Python interpreter is still functional at this point. -- http://mail.python.org/mailman/listinfo/python-list
Re: index nested lists
Alex wrote: On 28 Lug, 15:12, Andreas Tawn andreas.t...@ubisoft.com wrote: hi at all, If I have this list: lista ['ciao', 1, ['mela', 'pera', 'banana'], [1, 2, 3]] if I want enumerate elements...I can see: for parola in lista: print lista[i] i = i + 1 ciao 1 ['mela', 'pera', 'banana'] [1, 2, 3] but, if I want to enumerate elements about nested lists ??, something like: ciao 1 mela pera banana 1 2 3 ...How can I do ?? Alex -- http://mail.python.org/mailman/listinfo/python-list You could do something like this. def printNestedList(lst): if isinstance(lst, list): for element in lst: printNestedList(element) else: print lst myList = ['ciao', 1, ['mela', 'pera', 'banana'], [1, 2, 3]] printNestedList(myList) thanks a lot ! Alex One hidden suggestion in Andreas answer is to write your code in english, if you can :o) JM -- http://mail.python.org/mailman/listinfo/python-list
Re: bad certificate error
On Tue, 28 Jul 2009 03:35:55 -0700 (PDT), jakecjacobson jakecjacob...@gmail.com wrote: [snip] Invalid how? Self signed certificate? Domain mismatch? Expired certificate? It is a server name mismatch. Python 2.4 is not capable of allowing you to customize this verification behavior. It is hard coded to let OpenSSL make the decision about whether to accept the certificate or not. Either M2Crypto or pyOpenSSL will let you ignore verification errors. The new ssl module in Python 2.6 may also as well. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: bad certificate error
On Jul 28, 9:48 am, Jean-Paul Calderone exar...@divmod.com wrote: On Tue, 28 Jul 2009 03:35:55 -0700 (PDT), jakecjacobson jakecjacob...@gmail.com wrote: [snip] Invalid how? Self signed certificate? Domain mismatch? Expired certificate? It is a server name mismatch. Python 2.4 is not capable of allowing you to customize this verification behavior. It is hard coded to let OpenSSL make the decision about whether to accept the certificate or not. Either M2Crypto or pyOpenSSL will let you ignore verification errors. The new ssl module in Python 2.6 may also as well. Jean-Paul Thanks, I will look into these suggestions. -- http://mail.python.org/mailman/listinfo/python-list
Questions about unicodedata in python 2.6.2
I am trying to build python 2.6.2 from the source by following the instructions in README that comes with the source. The configure and make steps are fine, but there is an error in make install step. This make install attempts to build a lot of lib, and it complains about the lack of unicodedata shared object, I looked at the source tree and the build result, unicodedata.so does not exist. I further notice that in Modules/Setup.dist, the line for unicodedata.c is commented out by default. So I uncomment it, and experiment with rebuilding everything. This time, with or without re-configure, the make step failed with a link-time error when linking for libpython2.6.a due to undefined reference to 'initunicodedata'. This symbol is defined in unicodedata.c, but unicodedata.o is not used in linking for libpython2.6.a, hence the error. So this is a problem in the generated Makefile. Does anyone know what special things I have to do to avoid such error? Is there any known problems in the configure/make files in the python 2.6.2 source code that require special patch? Is unicodedata.c really needed in python 2.6.2? If it is needed, why it is commented out by default in Modules/Setup.dist? If it is not needed, why make install attempts to use it in compiling the libraries? Why those libraries are not designed to be compiled in the make step, but in the install step? Thanks for your help! - Weidong -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions about unicodedata in python 2.6.2
On Jul 28, 9:54 am, Weidong li.weid...@gmail.com wrote: I am trying to build python 2.6.2 from the source by following the instructions in README that comes with the source. The configure and make steps are fine, but there is an error in make install step. This make install attempts to build a lot of lib, and it complains about the lack of unicodedata shared object, I looked at the source tree and the build result, unicodedata.so does not exist. I further notice that in Modules/Setup.dist, the line for unicodedata.c is commented out by default. So I uncomment it, and experiment with rebuilding everything. This time, with or without re-configure, the make step failed with a link-time error when linking for libpython2.6.a due to undefined reference to 'initunicodedata'. This symbol is defined in unicodedata.c, but unicodedata.o is not used in linking for libpython2.6.a, hence the error. So this is a problem in the generated Makefile. Does anyone know what special things I have to do to avoid such error? Is there any known problems in the configure/make files in the python 2.6.2 source code that require special patch? Is unicodedata.c really needed in python 2.6.2? If it is needed, why it is commented out by default in Modules/Setup.dist? If it is not needed, why make install attempts to use it in compiling the libraries? Why those libraries are not designed to be compiled in the make step, but in the install step? Thanks for your help! - Weidong To add some info: This experiment was done on Linux, Ubuntu 8.x. -- http://mail.python.org/mailman/listinfo/python-list
Re: len() should always return something
On Friday 24 July 2009 11:58:36 am Phillip M. Feldman wrote: I've been converting Matlab codes to Python. In Matlab, a scalar is just a one-by-one matrix and has a length of 1. This convention seems no less arbitrary to me than Python's convention that the concept of length is not applicable to ints and floats. Are you sure it isn't? (as opposed to being tainted by matlab?). Almost everywhere, a scalar and a tuple are different things. How many elements are inside the number 7? If you assume that 7 is a matrix, why should it be a two-dimensional matrix? Why not a vector, or a three dimensional matrix instead? (I don't use matlab, but in octave, size(7) returns [1,1], not [1] or [1,1,1,1]). That seems even more arbitrary to me. Of course, in a language like Matlab, that assumes that everything is a matrix, it makes sense for scalars to be mapped to a useful matrices. But that assumption is not natural. Even pure math makes a difference between scalars and vectors. Matrix x Matrix multiplication is not always defined (even when the second matrix contains exactly one element), while Matrix x Scalar always is. (Octave, btw, will demote a two-dimensional 1x1 matrix to a scalar for Matrix multiplication, which may hide errors) If you are converting from matlab, I'd say you have biggest things to worry about. As you said, you can just replace the len function (even safer may be to do [1]). Assignment, for instance, is /very/ different. If there is only a single measurement, it is reasonable to allow the calling program to pass a scalar without wrapping it up into a list or array. I try to avoid those automatic conversions, on the long run, I believe that most of them make the code more confusing for the caller. If you feel that you must allow that, my suggestion would be to create a method that will ensure that what you receive is a list (or whatever) and coerce its argument if not, and call that one at the beginning of your methods. Regards, [1] this will define len for any object, not only int and floats. === def size(x): try: return len(x) except TypeError: return 1,1 === -- Luis Zarrabeitia (aka Kyrie) Fac. de Matemática y Computación, UH. http://profesores.matcom.uh.cu/~kyrie -- http://mail.python.org/mailman/listinfo/python-list
Re: FTP Offset larger than file.
Bakes ba...@ymail.com writes: The error I get is: ftplib.error_temp: 451-Restart offset 24576 is too large for file size 22852. 451 Restart offset reset to 0 which tells me that the local file is larger than the external file, by about a kilobyte. Certainly, the local file is indeed that size, so my local script is doing the right things. I do wonder what is going wrong, can anyone enlighten me? I'd say you failed to take buffering into account. You write into a buffered file, yet you use os.path.getsize() to find out the current file size. If the data is not yet flushed, you keep re-reading the same stuff from the remote file, and writing it out. Once the buffer is flushed, your file will contain more data than was retrieved from the remote side, and eventually this will result in the error you see. As a quick fix, you can add a file.flush() line after the file.write(...) line, and the problem should go away. -- http://mail.python.org/mailman/listinfo/python-list
Python-URL! - weekly Python news and links (Jul 28)
QOTW: But there's another principle at work here that's less well known, and that was first articulated to me by Robert Dewar: You can remove linear factors by profiling, but it's much harder to undo bad algorithmic decisions. In particular, whether a program runs in O(n) or O(n^2) sometimes depends on decisions that have to be frozen fairly early in the design. - Andrew Koenig Comparing the performance of the same algorithm using many compilers: CPython, psyco, Cython, ShedSkin, Unladen Swallow, Java, C and D: http://groups.google.com/group/comp.lang.python/browse_thread/thread/8d793c46903cc0b6/ MRAB has written a new implementation of re module with many new features, and he's looking for feedback: http://groups.google.com/group/comp.lang.python/browse_thread/thread/16c139b0a52ab023/ Importing two modules with the same name from different directories: http://groups.google.com/group/comp.lang.python/browse_thread/thread/3cb83a30e1b2c202/ Cleanly exiting an application, even if it gets killed by a signal: http://groups.google.com/group/comp.lang.python/browse_thread/thread/d60b8e0d93aeaaf9/ How can a child thread notify a parent thread of its status? http://groups.google.com/group/comp.lang.python/browse_thread/thread/d1d7f55716aacedc/ How to attach a docstring to global constants/variables? http://groups.google.com/group/comp.lang.python/browse_thread/thread/ac54186ad873036a/ In Python -unlike other languages- it does not make sense to treat numbers (scalars) as vectors of length 1: http://groups.google.com/group/comp.lang.python/browse_thread/thread/3ef498c906bd7e2d/ isinstance may take a tuple of types as its second argument: why a tuple, and not a list, or a set? http://mail.python.org/pipermail/python-list/2009-July/721205.html How to overcome the normal 2GB allocation limit of Windows XP, 32bits: http://groups.google.com/group/comp.lang.python/browse_thread/thread/59851df6e54f9ef0/ Distinguishing active generators from exhausted ones: http://groups.google.com/group/comp.lang.python/browse_thread/thread/9ff179e8cb5e9bc/ Peter Otten must be, undoubtedly, Sherlock Holmes reincarnated: http://groups.google.com/group/comp.lang.python/browse_thread/thread/838177c8a37d2b7c/ And Piet van Oostrum is not much behind him: http://groups.google.com/group/comp.lang.python/browse_thread/thread/d1f8627413cd3c4e/ 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 Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish the efforts of Python enthusiasts: http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the Planet sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes podcasts ... to help people learn Python ... Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ 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/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.orggroup=gmane.comp.python.develsort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few
Re: Questions about unicodedata in python 2.6.2
Weidong schrieb: I am trying to build python 2.6.2 from the source by following the instructions in README that comes with the source. The configure and make steps are fine, but there is an error in make install step. This make install attempts to build a lot of lib, and it complains about the lack of unicodedata shared object, unicodedata is usually build as a shared library and not linked into the Python core. How did you configure Python? The usual prodecure is: ./configure make sudo make install On Unix the preferred option for ./configure is --enable-unicode=ucs4. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: FTP Offset larger than file.
On 28 July, 15:01, Hrvoje Niksic hnik...@xemacs.org wrote: Bakes ba...@ymail.com writes: The error I get is: ftplib.error_temp: 451-Restart offset 24576 is too large for file size 22852. 451 Restart offset reset to 0 which tells me that the local file is larger than the external file, by about a kilobyte. Certainly, the local file is indeed that size, so my local script is doing the right things. I do wonder what is going wrong, can anyone enlighten me? I'd say you failed to take buffering into account. You write into a buffered file, yet you use os.path.getsize() to find out the current file size. If the data is not yet flushed, you keep re-reading the same stuff from the remote file, and writing it out. Once the buffer is flushed, your file will contain more data than was retrieved from the remote side, and eventually this will result in the error you see. As a quick fix, you can add a file.flush() line after the file.write(...) line, and the problem should go away. Thank you very much, that worked perfectly. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help understanding the decisions *behind* python?
On Friday 24 July 2009 11:07:30 am Inky 788 wrote: On Jul 23, 3:42 am, Hendrik van Rooyen hend...@microcorp.co.za if you think it is contrived, then please consider how you would keep track of say the colour of a pixel on a screen at position (x,y) - this is about the simplest natural tuple format and example. My guess is that this is probably the way most people do it: [...] def make_array_of_pixels(num_columns, num_rows): [...] If you need to hold /every/ pixel on the screen, it makes sense to have a bidimentional array of points and colors. But if you need to hold a non-rectangular subset, or even a subset that doesn't need to be rectangular, you can either use dicts, or ... do what you did. Most people will use the less contrived version of: screen = {} screen[1,2] = (rand(), rand(), rand()) (btw, in your make_a_pixel function, unless you want to make the pixels updatable in place, you should also be using a tuple). Sparse datasets are extremely common, and dicts are a good way to [temporarily] store them. As someone mentioned before, dictionaries are essential to python. Don't go out of your way to avoid them, unless you have a /reason/ to do it. Btw, def get_color(point): return screen[point] is way more readable (and less obscure) than def get_color(point): return rows_of_pixels[point[0]][point[1]] Regards, -- Luis Zarrabeitia (aka Kyrie) Fac. de Matemática y Computación, UH. http://profesores.matcom.uh.cu/~kyrie -- http://mail.python.org/mailman/listinfo/python-list
Re: initializing with empty list as default causes freaky problems
Quoting Reckoner recko...@gmail.com: Hi, Observe the following: In [202]: class Foo(): .: def __init__(self,h=[]): .: self.h=h [...] In [207]: f.h.append(10) In [208]: f.h Out[208]: [10] In [209]: g.h Out[209]: [10] The question is: why is g.h updated when I append to f.h? Shouldn't g.h stay []? What you are seeing is basically the same that happens here: === In [1]: def f(l=[]): ...: l.append(1) ...: print l ...: In [2]: f() [1] In [3]: f() [1, 1] In [4]: f() [1, 1, 1] === The problem is that the default value [] is evaluated only once, at function creation time, and not at invocation. Thus, every call to the function shares the same default object. That is consistent with python's function type: the def construct just creates a function object and initializes it with the code, argument list and default values. That means that the default value are part of the function object itself, regardless of when/if it is called: === In [5]: f.func_defaults Out[5]: ([1, 1, 1],) === The recommended way of dealing with this case (mutable default arguments) is: def f(l = None): if l is None: l = [] # the code goes here. (in your case, your g.__init__ and f.__init__ methods share the same Foo.__init__ function, and thus, share the same default value []) That is a very common python gotcha, and I think it is well documented in the standard doc (but I can't find it right now, sorry). Unfortunately, it doesn't become intuitive until you've spent a while understanding python's execution model (and then you suddenly realize that it just makes sense). [And now I wonder... how other languages do it? I've spent so much time with python that reevaluating the default argument on invocation feels clumsy, but I'm obviously tainted now...] Regards, -- Luis Zarrabeitia Facultad de Matemática y Computación, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu -- http://mail.python.org/mailman/listinfo/python-list
Re: FTP Offset larger than file.
On 28 July, 15:18, Bakes ba...@ymail.com wrote: On 28 July, 15:01, Hrvoje Niksic hnik...@xemacs.org wrote: Bakes ba...@ymail.com writes: The error I get is: ftplib.error_temp: 451-Restart offset 24576 is too large for file size 22852. 451 Restart offset reset to 0 which tells me that the local file is larger than the external file, by about a kilobyte. Certainly, the local file is indeed that size, so my local script is doing the right things. I do wonder what is going wrong, can anyone enlighten me? I'd say you failed to take buffering into account. You write into a buffered file, yet you use os.path.getsize() to find out the current file size. If the data is not yet flushed, you keep re-reading the same stuff from the remote file, and writing it out. Once the buffer is flushed, your file will contain more data than was retrieved from the remote side, and eventually this will result in the error you see. As a quick fix, you can add a file.flush() line after the file.write(...) line, and the problem should go away. Thank you very much, that worked perfectly. Actually, no it didn't. That fix works seamlessly in Linux, but gave the same error in a Windows environment. Is that expected? -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a dream language: sounds like Python to me.
Matlab, from The Mathworks, has a companion product called Simulink. This allows the user to graphically build ‘algorithms’ in block form. There is a similar Python function. Where can I find a Python functionality like simulink ? thanks, Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list
Re: Internal Math Library of Numpy
On Tue, Jul 28, 2009 at 10:09 PM, Nanime Puloskinpulo...@gmail.com wrote: Does Numpy use Python's standard math library when calculating elementary functions such as exp(x) and acos(x)? It depends on the dtype: for fundamental types (float, int, etc...), the underlying implementation is whatever the (C) math library provides. If the functionality is not there, we have our own custom implementation (but exp and acos happen to be mandatory - if they are not detected, the build fail). Also, what is the internal library of Numpy and Python's standard math library? Is it platform independent? I don't know for python, but for numpy, we have our own math library on top of whatever the platform provides (which is not much on windows, for example). There is an ongoing effort in numpy to provides a portable, pure C (independent of the python runtime) math library. The goal is to have a portable C99 math library, and more later hopefully. cheers, David -- http://mail.python.org/mailman/listinfo/python-list
Re: New implementation of re module
Aahz wrote: In article mailman.3787.1248712420.8015.python-l...@python.org, MRAB pyt...@mrabarnett.plus.com wrote: I've been working on a new implementation of the re module. The details are at http://bugs.python.org/issue2636, specifically from http://bugs.python.org/issue2636#msg90954. I've included a .pyd file for Python 2.6 on Windows if you want to try it out. How does it handle the re module's unit tests? Basically, it passes all those tests I expect it to pass. :-) It fails those where the intended behaviour has changed, such as re.sub treating unmatched groups as empty strings, as requested in http://bugs.python.org/issue1519638. -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
Hendrik van Rooyen wrote: On Monday 27 July 2009 16:49:25 Aahz wrote: In article mailman.3765.1248685391.8015.python-l...@python.org, Hendrik van Rooyen hend...@microcorp.co.za wrote: On Sunday 26 July 2009 21:26:46 David Robinow wrote: I'm a mediocre programmer. Does this mean I should switch to PHP? I have searched, but I can find nothing about this mediocre language. Could you tell us more? :-P (For anyone who is confused by Hendrik's humor, he is saying that David was referring to a programming language named mediocre. English grammar is confusing!) This is true - I intended, when I started the post, to make a crack about how he knew that he was mediocre - If there were some exam or test that you have to pass or fail to be able to make the claim to mediocrity. I was imagining a sort of devil's rating scale for programmers, that could cause one to say things like: I am studying hard so that I can get my mediocre certificate, and one day I hope to reach hacker rank. And then the similarity to I am a COBOL programmer struck me, and I abandoned the ratings. If you were a COBOL programmer, would you want to shout about it? :-) -- http://mail.python.org/mailman/listinfo/python-list
need help using Tkinter
i wanted to ask you if one of you could help me to use Tkinter. i'm trying to just create a simple GUI for which I have provided the code for below. # Simple GUI # Demonstrates creating a window from Tkinter import * # create the root window root = Tk () # modify the window root.title(Simple GUI) root.geometry(200x100) # kick off the window's event loop root.mainloop() i saved the file as both simple_gui.py and simple_gui.pyw. when i try to run simple_gui.pyw i don't get anything and when i try to run simple_gui.py i get the following: Traceback (most recent call last): File C:\Python-Study\Chapter10\simple_gui.py, line 4, in module ImportError: No module named Tkinter i tried to google search this and there were some threads that were saying to install tcl but that does not work. I did check the Lib directory under the Python directory and I did not see a Tkinter module anywhere which I think is the problem. Do you know how I would go about with getting this module and if that is not the problem or if you think it might be caused by something else, can you please give me some guidance? i even reinstalled python 3.1 which i got from www.python.org. i still do not see the Tkinter module in the lib directory. thank you for all your help. manzur -- http://mail.python.org/mailman/listinfo/python-list
Re: WSDL and XML generation
Hi you can generate the WSDl with soaplib [1], and you can view web.py or django for this: for web.py - http://webpy.org/cookbook/webservice for django - http://www.djangosnippets.org/snippets/979/ [1]= http://trac.optio.webfactional.com/ Hi all Newbie in Python, i am looking for some pointers (or better existing modules) to do the followings: - generate (correct) XML messages from a WSDL file - make some modifications inside XML messages *before* sending them to the server hosting the Web services (described by previously mentionned WSDL file) - parse the answer. Some ideas ? Thanks in advance Stephane -- http://mail.python.org/mailman/listinfo/python-list signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: need help using Tkinter
Manzur Ahmed wrote: i wanted to ask you if one of you could help me to use Tkinter. i'm trying to just create a simple GUI for which I have provided the code for below. # Simple GUI # Demonstrates creating a window from Tkinter import * # create the root window root = Tk () # modify the window root.title(Simple GUI) root.geometry(200x100) # kick off the window's event loop root.mainloop() i saved the file as both simple_gui.py and simple_gui.pyw. when i try to run simple_gui.pyw i don't get anything and when i try to run simple_gui.py i get the following: Traceback (most recent call last): File C:\Python-Study\Chapter10\simple_gui.py, line 4, in module ImportError: No module named Tkinter i tried to google search this and there were some threads that were saying to install tcl but that does not work. I did check the Lib directory under the Python directory and I did not see a Tkinter module anywhere which I think is the problem. Do you know how I would go about with getting this module and if that is not the problem or if you think it might be caused by something else, can you please give me some guidance? i even reinstalled python 3.1 which i got from www.python.org http://www.python.org/. i still do not see the Tkinter module in the lib directory. thank you for all your help. There are some differences between Python 3.x and Python 2.x. In Python 3.1 the module is called tkinter, not Tkinter (names are case-sensitive). -- http://mail.python.org/mailman/listinfo/python-list
Re: M2Crypto hangs on this URL
Martin P. Hellwig wrote: John Nagle wrote: John Nagle wrote: John Nagle wrote: There's something strange about this URL: https://sagar310.pontins.com/sraep/; ... It looks to me like the SSL handshake is not done properly from the server side. Compare the output of: openssl s_client -host sagar310.pontins.com -port 443 -debug -showcerts -msg With (for example): openssl s_client -host www.google.com -port 443 -debug -showcerts -msg OpenSSL is clearly not happy with that site. But it doesn't hang. openssl s_client -host sagar310.pontins.com -port 443 -debug -showcerts -msg eventually prints Verify return code: 19 (self signed certificate in certificate chain) That's weird, because there's a Verisign certificate in the chain. That site is somehow mishandling its certs. My problem, though, is that M2Crypto 0.17 is hanging for hours to days on those connections. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: FTP Offset larger than file.
Bakes ba...@ymail.com writes: As a quick fix, you can add a file.flush() line after the file.write(...) line, and the problem should go away. Thank you very much, that worked perfectly. Actually, no it didn't. That fix works seamlessly in Linux, but gave the same error in a Windows environment. Is that expected? Consider opening the file in binary mode, by passing the 'wb' and 'ab' modes to open instead of 'w' and 'a' respectively. On Windows, python (and other languages) will convert '\n' to '\r\n' on write. -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions about unicodedata in python 2.6.2
On Jul 28, 10:17 am, Christian Heimes li...@cheimes.de wrote: unicodedatais usually build as a shared library and not linked into the Python core. How did you configure Python? The usual prodecure is: ./configure make sudo make install On Unix the preferred option for ./configure is --enable-unicode=ucs4. Christian Thanks for your response! I configured it in the same way as you said, but without --enable-unicode=ucs4. The ocnfig.log shows that checking for UCS-4 was failed. So I assume that by default UCS-2 was used. There was no other problme in the make step. The problem was in the sudo make install step, where there were errors in building libraries / test libraries that need unicodedata.so which did not exist. I also tried to use make -i to let it complete the building to ignore that error. In the end, I still did not see unicodedata.so in the build result. It seems that the Makefile did not even try to build unicodedata.so. Maybe something went wrong in my configuration? - Weidong -- http://mail.python.org/mailman/listinfo/python-list
Re: Wrapping prstat on Solaris
On Jul 27, 10:26 am, s...@pobox.com wrote: At work we currently use top to monitor ongoing system utilization on our Solaris systems. As time has moved on though, use of top has become problematic. Our admins want us to switch to prstat, Sun's top-like command. It works fine however doesn't emit a timestamp at each display interval, so it's essentially impossible looking at a prstat output file to determine when the particular screen was emitted. If figured, No problem. I'll just write a little wrapper. Alas, that is proving harder than I thought. I can run prstat directing output to a file and it seems to blast out a block of lines every N seconds, but when run from inside a Python script I can't seem to make the damn thing not massively buffer its output. Accordingly, my script doesn't really see the output as its emitted, so the timestamp line it prepends to a block of output is off. I'm currently using subprocess.Popen like so: os.environ[TERM] = dumb cmd = prstat -c %s % .join(sys.argv[1:]) pipe = Popen(cmd, shell=True, bufsize=1, stdout=PIPE).stdout I've tried these other variants as well: * prefacing the prstat command with unbuffer (the tcl/expect thingamabob) * explicitly redirect the prstat output to /dev/stdout * setting bufsize to 0 * used os.popen instead of Subprocess.Popen Nothing seems to help. I always seem to see about 30 seconds of data at once (I'm currently using a 5-second interval and 10 lines of output). I would have expected that prstat would simply flush stdout after each block of output. Any ideas about how to get prstat to cooperate better? Thanks, -- Skip Montanaro - s...@pobox.com -http://www.smontanaro.net/ That's more than a dress. That's an Audrey Hepburn movie. -- Jerry Maguire Hey Skip, You haven't told us how you are actually reading from prstat's output pipe, which may be the cause. For instance, if you are doing for line in pipe: print line ... then this could cause your buffering issue. Instead try using readline(): while True: line = pipe.readline() ... -- http://mail.python.org/mailman/listinfo/python-list
Python as active script script language=python
I'm using Activestate python, For older version of python, I know that we can register python as active script by registering it through win32comext.axscript.client pyscript.py And to do that I need to change something in this pyscript.py before running pyscript_rexec.py(http://fastq.com/~sckitching/Python/ win32_activeX_pyscript.htm), but I can't find similar thing with python 2.6.2 I can't find the line that need to be changed. Can someone kindly show me how to enable python26 as an active script for IE? Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Re: The longest word
On Jul 28, 7:55 am, NiklasRTZ nikla...@gmail.com wrote: Sincere thanks for strengthening python's superior flexibility. Same function also works around an exploding index problem returning results for longest word where otherwise a word with whitespace crashes the index: Babelfish? -- http://mail.python.org/mailman/listinfo/python-list
Re: FTP Offset larger than file.
Bakes wrote: On 28 July, 15:18, Bakes ba...@ymail.com wrote: On 28 July, 15:01, Hrvoje Niksic hnik...@xemacs.org wrote: Bakes ba...@ymail.com writes: The error I get is: ftplib.error_temp: 451-Restart offset 24576 is too large for file size 22852. 451 Restart offset reset to 0 which tells me that the local file is larger than the external file, by about a kilobyte. Certainly, the local file is indeed that size, so my local script is doing the right things. I do wonder what is going wrong, can anyone enlighten me? I'd say you failed to take buffering into account. You write into a buffered file, yet you use os.path.getsize() to find out the current file size. If the data is not yet flushed, you keep re-reading the same stuff from the remote file, and writing it out. Once the buffer is flushed, your file will contain more data than was retrieved from the remote side, and eventually this will result in the error you see. As a quick fix, you can add a file.flush() line after the file.write(...) line, and the problem should go away. Thank you very much, that worked perfectly. Actually, no it didn't. That fix works seamlessly in Linux, but gave the same error in a Windows environment. Is that expected? This is a text file you're transferring. And you didn't specify wb. So the Windows size will be larger than the Unix size, since you're expanding the newline characters. getsize() is looking at the size after newlines are expanded to 0d0a, while The remote file, presumably a Unix system likely has just has 0a. I think you'd do best just keeping track of the bytes you've written. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions about unicodedata in python 2.6.2
Weidong wrote: Thanks for your response! I configured it in the same way as you said, but without --enable-unicode=ucs4. The ocnfig.log shows that checking for UCS-4 was failed. So I assume that by default UCS-2 was used. There was no other problme in the make step. Correct The problem was in the sudo make install step, where there were errors in building libraries / test libraries that need unicodedata.so which did not exist. 'make install' shouldn't compile any libraries if you run 'make' prior to 'make install'. I suggest you start again with a clean build tree of Python 2.6.2. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: New implementation of re module
On 27 Jul., 21:27, Wolfgang Rohdewald wolfg...@rohdewald.de wrote: how do I compile _regex.c on Linux? This simple setup.py file should do the trick: from distutils.core import setup, Extension setup(name='regex', version='1.0', py_modules = ['regex'], ext_modules=[Extension('_regex', ['_regex.c'])], ) Also, you need to copy unicodedata_db.h from the Modules directory of the Python source tree to your working directory, since this file apparently is not installed into the include directory of a Python installation. I get an error for Python 2.5 on Mac OS X 10.4 and Linux though. Seems that the module is not compatible with Python 2.5. _regex.c: In function 'getstring': _regex.c:2425: error: invalid type argument of '-' _regex.c: In function 'getstring': _regex.c:2425: error: invalid type argument of '-' lipo: can't figure out the architecture type of: /var/tmp// ccT3oDXD.out error: command 'gcc' failed with exit status 1 resp. on Linux: _regex.c: In function 'getstring': _regex.c:2425: warning: implicit declaration of function 'Py_TYPE' _regex.c:2425: error: invalid type argument of '-' _regex.c: In function 'get_match_replacement': _regex.c:2900: warning: implicit declaration of function 'PyLong_AsSsize_t' error: command 'gcc' failed with exit status 1 With the official Python 2.6 distribution for Mac OS X it works. Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: New implementation of re module
Christopher Arndt wrote: On 27 Jul., 21:27, Wolfgang Rohdewald wolfg...@rohdewald.de wrote: how do I compile _regex.c on Linux? This simple setup.py file should do the trick: from distutils.core import setup, Extension setup(name='regex', version='1.0', py_modules = ['regex'], ext_modules=[Extension('_regex', ['_regex.c'])], ) Also, you need to copy unicodedata_db.h from the Modules directory of the Python source tree to your working directory, since this file apparently is not installed into the include directory of a Python installation. I get an error for Python 2.5 on Mac OS X 10.4 and Linux though. Seems that the module is not compatible with Python 2.5. _regex.c: In function 'getstring': _regex.c:2425: error: invalid type argument of '-' _regex.c: In function 'getstring': _regex.c:2425: error: invalid type argument of '-' lipo: can't figure out the architecture type of: /var/tmp// ccT3oDXD.out error: command 'gcc' failed with exit status 1 resp. on Linux: _regex.c: In function 'getstring': _regex.c:2425: warning: implicit declaration of function 'Py_TYPE' _regex.c:2425: error: invalid type argument of '-' _regex.c: In function 'get_match_replacement': _regex.c:2900: warning: implicit declaration of function 'PyLong_AsSsize_t' error: command 'gcc' failed with exit status 1 With the official Python 2.6 distribution for Mac OS X it works. The source code is intended to replace the current 're' module in Python 2.7 (and I'll be porting it to Python 3.2), so I'm not that worried about Python versions earlier than 2.6 for testing, although if there's sufficient need then I could tweak the sources for 2.5. -- http://mail.python.org/mailman/listinfo/python-list
Language detector for Python using en-gram.
One of my friend suggested me to do a language detector for python.At present the language detector in python is in uni-gram mode and i have planned to do it in en-gram mode.Kindly give me your suggestion as i am doing this as my final year project. With Anticipation, Varun V. Kumar -- http://mail.python.org/mailman/listinfo/python-list
Re: M2Crypto hangs on this URL
John Nagle wrote: Martin P. Hellwig wrote: John Nagle wrote: John Nagle wrote: John Nagle wrote: There's something strange about this URL: https://sagar310.pontins.com/sraep/; ... It looks to me like the SSL handshake is not done properly from the server side. Compare the output of: openssl s_client -host sagar310.pontins.com -port 443 -debug -showcerts -msg With (for example): openssl s_client -host www.google.com -port 443 -debug -showcerts -msg OpenSSL is clearly not happy with that site. But it doesn't hang. openssl s_client -host sagar310.pontins.com -port 443 -debug -showcerts -msg eventually prints Verify return code: 19 (self signed certificate in certificate chain) That's weird, because there's a Verisign certificate in the chain. That site is somehow mishandling its certs. My problem, though, is that M2Crypto 0.17 is hanging for hours to days on those connections. John Nagle Well it hanged when I tried it, however the site now does return something when using Firefox, so I assume somebody is doing some work there or the server decided to do something else. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' -- http://mail.python.org/mailman/listinfo/python-list
Re: Gracefully exiting CLI application
Il Tue, 28 Jul 2009 14:31:56 +0100, Nobody ha scritto: Killed by what means? Ctrl-C sends SIGINT which is converted to a KeyboardInterrupt exception. This can be caught, or if it's allowed to terminate the process, any exit handlers registered via atexit.register() will be used. For other signals, you can install a handler with signal.signal(). This can call sys.exit() or raise an exception (e.g. KeyboardInterrupt). OTOH, if the process is terminated by SIGKILL, there's nothing you can do about it. And although it's possible to trap SIGSEGV, you shouldn't assume that the Python interpreter is still functional at this point. I'm really sorry guys, I forgot to mention that the platform is win32, where there is minimal support to signals. Anyway I've found a solution with win32api.SetConsoleCtrlHandler that installs a event handler which traps all windows events, CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, and CTRL_SHUTDOWN_EVENT included. David. -- http://mail.python.org/mailman/listinfo/python-list
C function taking double pointer to a structure variable as OUTPUT parameter
Hi, Everyone, I am a newbie to both Swig and Python. I am trying to export a set of C APIs to Python. My C function is int getInfor( char* name, int height, int weight, Infor** infor) //where infor is an OUTPUT parameter { .. *infor = (Infor*)malloc(sizeof(Infor)); .. } nbsp; The declare of structure Infor is : nbsp;typedef struct { nbsp;charnbsp;nbsp;name[20]; nbsp;intnbsp;nbsp;nbsp;height; nbsp;intnbsp;nbsp;nbsp;weight; } Infor nbsp; When wrote the below lines in the interface file named Extest.i %module Extest %{ #include Extest.h %} %typemap(out) Infor **OUTPUT {Infor **c} %apply int *OUTPUT {int *c} %include Extest.h nbsp; And then, How to write testing python file to call the function named getInfor()? such as in test.py nbsp; infor = Extest.Infor() res = Extest.getInfor(Test Name, 175, 80, infor) nbsp; when run upper's test.py, Error occured. The message is TypeError: in method 'getInfor', argument 4 of type 'Infor **' nbsp; How to write the test.py to transfer thenbsp; 'Infor **' type's parameter? After putting lot of trail and errors, I am writing this mail. Could you please help me to write the test.py or swig interface file for the above function? Thank you, jemmy Awaiting you-- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
Xah Lee wrote: PHP is functional. PHP is functional, as in it functions!. PHP is not functional, as in it ain't functions! -- http://mail.python.org/mailman/listinfo/python-list
Re: Discovery IP in connection
Thanks, all! I didn't tried to print addr. :-( sorry all. I'm learning python yet. Thanks again ! On Mon, Jul 27, 2009 at 8:23 PM, Piet van Oostrump...@cs.uu.nl wrote: Djames Suhanko djames.suha...@gmail.com (DS) wrote: DS Hello,all! DS I wrote a little programa that listening UDP packets. A can receive DS the messages, but I can't see the the origin IP. DS How can I to get the remote IP address in connection? What do you think the addr is for in data, addr = mySocket.recvfrom(100)? DS My source: DS #!/usr/bin/env python DS import socket DS mySocket = socket.socket ( socket.AF_INET, socket.SOCK_DGRAM ) DS mySocket.bind ( ( '', 514 ) ) DS data, addr = mySocket.recvfrom(100) DS print data -- Piet van Oostrum p...@cs.uu.nl URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list -- Djames Suhanko LinuxUser 158.760 -- http://mail.python.org/mailman/listinfo/python-list
Re: bad certificate error
jakecjacobson jakecjacob...@gmail.com (j) wrote: j On Jul 28, 9:48 am, Jean-Paul Calderone exar...@divmod.com wrote: On Tue, 28 Jul 2009 03:35:55 -0700 (PDT), jakecjacobson jakecjacob...@gmail.com wrote: [snip] Invalid how? Self signed certificate? Domain mismatch? Expired certificate? It is a server name mismatch. Python 2.4 is not capable of allowing you to customize this verification behavior. It is hard coded to let OpenSSL make the decision about whether to accept the certificate or not. Either M2Crypto or pyOpenSSL will let you ignore verification errors. The new ssl module in Python 2.6 may also as well. Jean-Paul j Thanks, I will look into these suggestions. j # cert_file is a PEM formatted certificate chain file. j connection = httplib.HTTPSConnection(host, int(port), key_file, j cert_file) What happens if you set cert_file to None? This would indicate that you are not interested in the server's certificate. By the way, is the cert_file you supply the certificate of the CA that signed the server's cert (in contrast to yours)? -- Piet van Oostrum p...@cs.uu.nl URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list
[ANN] Pyjamas 0.6pre2 Python Web Widget Set and Javascript Compiler
http://pyjs.org this is a pre-release announcement, 0.6pre2, of the pyjamas widget set and python-to-javascript compiler. there are over 110 entries in the CHANGELOG since the last stable release, 0.5p1, and so it was deemed sensible to invite people to test this version before its next stable release, 0.6. pyjamas, being a port of GWT to python, comprises four main components: * a stand-alone python-to-javascript compiler * a desktop-based wrapper around python-xpcom or pywebkitgtk * a browser DOM model wrapper interface * a widget set similar to pygtk2 / pyqt4, based on DOM manipulation significantly in the 0.6 series, pyjamas-desktop has been incorporated into the build: python Hello.py will start a stand-alone app (just as you would with pygtk2 or pyqt4) and pyjsbuild Hello will compile the javascript version(s). the combination means that pyjamas can run python applications - unmodified - in all major web browsers, or on the desktop (using gecko or webkit) in a similar fashion to adobe AIR. in the javascript version: somewhere along the line, a massive performance hit was introduced by accident. this has now been fixed. however, random desperate attempts to improve performance, before the mistake was corrected, mean that the pyjamas 0.6pre2 python-to-javascript compiler produces code that is stunningly quick. also in the 0.6pre2 release, strict python options have now been introduced, so that developers can expect much more support for the standard python 2.5 / 2.6 language semantics. the -O option disables many of these features, bringing a quite significant speed increase, by sacrificing python compatibility. that's just the way it has to be. downloads can be found by following the links from http://pyjs.org - sourceforge, code.google.com, pypi, all the usual places. lastly - thank you to everyone who's helped with pyjamas: bernd, bernd, jurgen, christian, kees, ondrej and many more, and especially thank you to the people who helped out by pointing out bugs in the 0.6pre1 release, please keep it up! l. -- http://mail.python.org/mailman/listinfo/python-list
instead of depending on data = array('h') .. write samples 1 by 1 to w = wave.open(wav.wav, w)
it says Wave_write.writeframes(data) will that mean from array import array is a must? this does the job: import oil import wave from array import array a = oil.Sa() w = wave.open(current.wav, w) w.setnchannels(2) w.setsampwidth(2) w.setframerate(44100) data = array('h') for gas in range(44100 * 5): a.breath() r = int(32767 * (a.pulse(1) + a.pulse(2) + a.pulse(3)) / 3.0) l = int(32767 * (a.pulse(4) + a.pulse(5) + a.pulse(6)) / 3.0) data.append(r) data.append(l) w.writeframes(data.tostring()) w.close() don't like array becoming so huge so tested this and it was also okay: for gas in range(44100 * 5): a.breath() data = array('h') r = int(32767 * (a.pulse(1) + a.pulse(2) + a.pulse(3)) / 3.0) l = int(32767 * (a.pulse(4) + a.pulse(5) + a.pulse(6)) / 3.0) data.append(r) data.append(l) w.writeframes(data.tostring()) but without array .. it becomes 15secs(3 times longer than was intended to be) of wav file: for gas in range(44100 * 5): a.breath() r = int(32767 * (a.pulse(1) + a.pulse(2) + a.pulse(3)) / 3.0) l = int(32767 * (a.pulse(4) + a.pulse(5) + a.pulse(6)) / 3.0) w.writeframes(hex(r)) w.writeframes(hex(l)) should i just be happy with depennding on using array? or is there a solution to make the last one work properly? tia -- SaRiGaMa's Oil Vending Orchestra is podcasting: http://sarigama.namaste.jp/podcast/rss.xml and supplying oil.py for free: http://oilpy.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
xlrd - insert column?
Does xlrd have the capability to insert a column? -- http://mail.python.org/mailman/listinfo/python-list
Re: New implementation of re module
On 28-07-2009, MRAB wrote: With the official Python 2.6 distribution for Mac OS X it works. The source code is intended to replace the current 're' module in Python 2.7 (and I'll be porting it to Python 3.2), so I'm not that worried about Python versions earlier than 2.6 for testing, although if there's sufficient need then I could tweak the sources for 2.5. I understand now why i could'nt compile it ! So, i would like if it's not too much work for you. -- William Dodé - http://flibuste.net Informaticien Indépendant -- http://mail.python.org/mailman/listinfo/python-list
Need help in passing a -c command argument to the interactive shell.
On my windows box I type = c:\xpython -c import re The result is = c:\x In other words, the Python interactive shell doesn't even open. What am I doing wrong? I did RTFM at http://www.python.org/doc/1.5.2p2/tut/node4.html on argument passing, but to no avail. -- http://mail.python.org/mailman/listinfo/python-list
Re: Extract images from PDF files
David, Thanks for your reply, I'll take a look at pdftohtml and see if it suits my needs. Thanks! Doug -- http://mail.python.org/mailman/listinfo/python-list
Re: time.strftime('%m-%d-%Y %H:%m:%S') to log is out of order
On Jul 22, 1:04 pm, davidj411 davidj...@gmail.com wrote: i think Piet van Oostrum has resolved my issue. good eyes! Well, he *is* Dutch... -Ben -- http://mail.python.org/mailman/listinfo/python-list
Deprecated sets module with Python 2.6
I would appreciate help on correcting a problem when trying to create an *.exe file using py2exe via GUI2exe with Python 2.6.2. When using GUI2exe to create an *.exe I always get the following warning during the compile process: C:\Python26\lib\site-packages\py2exe\build_exe.py:16: DeprecationWarning: the sets module is deprecated import sets and this results in the creation of an *.exe file that can not be executed. On the other hand, if I use the same procedure (on the same Python code) with Python 2.5, there are no warnings and the *.exe works fine. The procedure used is that given in the example Less simpler one at http://code.google.com/p/gui2exe/wiki/GUI2ExeExamplesin Any suggestions, help, ... would be greatly appreciated. Thanks, --V. -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help in passing a -c command argument to the interactive shell.
On Jul 28, 2009, at 4:16 PM, Bill wrote: On my windows box I type = c:\xpython -c import re The result is = c:\x In other words, the Python interactive shell doesn't even open. What am I doing wrong? Nothing! =) The -c option tells Python to execute the commands in the quotes as a Python program. It's as if you wrote a Python program that contained only import re and then executed that program. If you want to run the Python interpreter interactively, just type python (no quotes) at the command prompt and hit enter. I did RTFM at http://www.python.org/doc/1.5.2p2/tut/node4.html on argument passing, but to no avail. Yikes, that's the documentation for Python 1.5.2 which is nine years old! If that's the version you're running, then it's appropriate to read that documentation, but that's probably not the case. python --version (again, no quotes) should tell you what version you're running. HTH Philip -- http://mail.python.org/mailman/listinfo/python-list
Re: xlrd - insert column?
LeeRisq wrote: Does xlrd have the capability to insert a column? rd means ReaD, so there is nothing it could insert something to. Of course once you have read the data you can manipulate its structure how you like it. The counterpart is xlwt and it can write excel files however you like it. Regards Tino -- http://mail.python.org/mailman/listinfo/python-list
Re: Deprecated sets module with Python 2.6
Virgil Stokes wrote: I would appreciate help on correcting a problem when trying to create an *.exe file using py2exe via GUI2exe with Python 2.6.2. When using GUI2exe to create an *.exe I always get the following warning during the compile process: C:\Python26\lib\site-packages\py2exe\build_exe.py:16: DeprecationWarning: the sets module is deprecated import sets and this results in the creation of an *.exe file that can not be executed. On the other hand, if I use the same procedure (on the same Python code) with Python 2.5, there are no warnings and the *.exe works fine. The procedure used is that given in the example Less simpler one at http://code.google.com/p/gui2exe/wiki/GUI2ExeExamplesin Any suggestions, help, ... would be greatly appreciated. The 'sets' module is deprecated in Python 2.6 because 'set' was added as a new builtin class. I don't know why that would result in a .exe file that can't be executed. -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help in passing a -c command argument to the interactive shell.
Bill wrote: On my windows box I type = c:\xpython -c import re The result is = c:\x In other words, the Python interactive shell doesn't even open. What am I doing wrong? I did RTFM at http://www.python.org/doc/1.5.2p2/tut/node4.html on argument passing, but to no avail. You've told python to run the command import re which it's happily done before exiting. Simply type python, then at the prompt (default ) type whatever commands you wish, e.g. c:\Users\Mark\python\regexpython Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. import re help(re.compile) Help on function compile in module re: compile(pattern, flags=0) Compile a regular expression pattern, returning a pattern object. -- Kindest regards. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: need help using Tkinter
MRAB pyt...@mrabarnett.plus.com wrote: Manzur Ahmed wrote: i wanted to ask you if one of you could help me to use Tkinter. i'm trying to just create a simple GUI for which I have provided the code for below. There are some differences between Python 3.x and Python 2.x. In Python 3.1 the module is called tkinter, not Tkinter (names are case-sensitive). Further to the above, you can find my Tkinter tutorial (which uses Python 3.x) at http://www.tkdocs.com -- I hope this will provide some help in getting up to speed. Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Override a method but inherit the docstring
On Jul 26, 6:55 pm, a...@pythoncraft.com (Aahz) wrote: Nice! Maybe stick this on the Cookbook? http://code.activestate.com/recipes/576862/ Thanks for the suggestion, Shai. -- http://mail.python.org/mailman/listinfo/python-list
Re: New implementation of re module
In article mailman.3843.1248793153.8015.python-l...@python.org, MRAB pyt...@mrabarnett.plus.com wrote: Aahz wrote: In article mailman.3787.1248712420.8015.python-l...@python.org, MRAB pyt...@mrabarnett.plus.com wrote: I've been working on a new implementation of the re module. The details are at http://bugs.python.org/issue2636, specifically from http://bugs.python.org/issue2636#msg90954. I've included a .pyd file for Python 2.6 on Windows if you want to try it out. How does it handle the re module's unit tests? Basically, it passes all those tests I expect it to pass. :-) It fails those where the intended behaviour has changed, such as re.sub treating unmatched groups as empty strings, as requested in http://bugs.python.org/issue1519638. Then you should definitely publish to PyPI and post a message to c.l.py.announce to get more users. -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important. --Henry Spencer -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
On Tue, 28 Jul 2009 16:11:02 +0100, MRAB pyt...@mrabarnett.plus.com wrote: Hendrik van Rooyen wrote: On Monday 27 July 2009 16:49:25 Aahz wrote: In article mailman.3765.1248685391.8015.python-l...@python.org, Hendrik van Rooyen hend...@microcorp.co.za wrote: On Sunday 26 July 2009 21:26:46 David Robinow wrote: I'm a mediocre programmer. Does this mean I should switch to PHP? I have searched, but I can find nothing about this mediocre language. Could you tell us more? :-P (For anyone who is confused by Hendrik's humor, he is saying that David was referring to a programming language named mediocre. English grammar is confusing!) This is true - I intended, when I started the post, to make a crack about how he knew that he was mediocre - If there were some exam or test that you have to pass or fail to be able to make the claim to mediocrity. I was imagining a sort of devil's rating scale for programmers, that could cause one to say things like: I am studying hard so that I can get my mediocre certificate, and one day I hope to reach hacker rank. And then the similarity to I am a COBOL programmer struck me, and I abandoned the ratings. If you were a COBOL programmer, would you want to shout about it? :-) The last time I wrote anything in COBOL was sometime in the early 80s. Somehow that makes me feel good, heh. ciao, f -- “Using words to describe magic is like using a screwdriver to cut roast beef.” -- Tom Robbins -- http://mail.python.org/mailman/listinfo/python-list
Re: C function taking double pointer to a structure variable as OUTPUT parameter
fengmang_pyt...@sina.com schrieb: Hi, Everyone, I am a newbie to both Swig and Python. I am trying to export a set of C APIs to Python. If you are really dealing with a plain C-api, don't bother using SWIG - use ctypes. It comes with python =2.5, is availabe as extra module for earlier versions, and makes wrapping C-libs a breeze. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions about unicodedata in python 2.6.2
On Jul 28, 12:37 pm, Christian Heimes li...@cheimes.de wrote: 'make install' shouldn't compile any libraries if you run 'make' prior to 'make install'. I suggest you start again with a clean build tree of Python 2.6.2. Christian You are perfectly right. I started everything again after a make distclean. This time I configured it as follows: ./configure --enable-unicode=ucs2 --enable-shared to make things explicit, although I guess that the defaults would be the same even when --enable-unicode=ucs2 --enable-shared are not specified (in my case where ucs4 is not available). The Makefile generated then contains meaningful flags in RUNSHARED which was absent before. With this configuration, make was fine, except it only has the following problems: Failed to find the necessary bits to build these modules: bsddb185 gdbm sunaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name. That was not surprised because I did not have those available on my machine. The unicodedata.so was also created in the make process, and make install showed no problem. make test showed the following problems: test_aepack test_aepack skipped -- No module named aepack test_al test_al skipped -- No module named al test_anydbm Exception bsddb.db.DBRunRecoveryError: DBRunRecoveryError(-30974, 'DB_RUNRECOVERY: Fatal error, run database recovery -- PANIC: fatal region error detected; run recovery') in ignored I guess this is caused by the missing bsddb185. However, the problem is, make test seemed to be hanging at that fatal error. Do you know how critical are those failed tests? Thanks for your help! - Weidong -- http://mail.python.org/mailman/listinfo/python-list
Re: Deprecated sets module with Python 2.6
Virgil Stokes schrieb: I would appreciate help on correcting a problem when trying to create an *.exe file using py2exe via GUI2exe with Python 2.6.2. When using GUI2exe to create an *.exe I always get the following warning during the compile process: C:\Python26\lib\site-packages\py2exe\build_exe.py:16: DeprecationWarning: the sets module is deprecated import sets and this results in the creation of an *.exe file that can not be executed. On the other hand, if I use the same procedure (on the same Python code) with Python 2.5, there are no warnings and the *.exe works fine. The procedure used is that given in the example Less simpler one at http://code.google.com/p/gui2exe/wiki/GUI2ExeExamplesin Any suggestions, help, ... would be greatly appreciated. If you don't need your app running on python2.3 and earlier, just remove the sets-module and replace it with the builtin set. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: FTP Offset larger than file.
On Jul 28, 5:36 pm, Dave Angel da...@ieee.org wrote: Bakes wrote: On 28 July, 15:18, Bakes ba...@ymail.com wrote: On 28 July, 15:01, Hrvoje Niksic hnik...@xemacs.org wrote: Bakes ba...@ymail.com writes: The error I get is: ftplib.error_temp: 451-Restart offset 24576 is too large for file size 22852. 451 Restart offset reset to 0 which tells me that the local file is larger than the external file, by about a kilobyte. Certainly, the local file is indeed that size, so my local script is doing the right things. I do wonder what is going wrong, can anyone enlighten me? I'd say you failed to take buffering into account. You write into a buffered file, yet you use os.path.getsize() to find out the current file size. If the data is not yet flushed, you keep re-reading the same stuff from the remote file, and writing it out. Once the buffer is flushed, your file will contain more data than was retrieved from the remote side, and eventually this will result in the error you see. As a quick fix, you can add a file.flush() line after the file.write(...) line, and the problem should go away. Thank you very much, that worked perfectly. Actually, no it didn't. That fix works seamlessly in Linux, but gave the same error in a Windows environment. Is that expected? This is a text file you're transferring. And you didn't specify wb. So the Windows size will be larger than the Unix size, since you're expanding the newline characters. getsize() is looking at the size after newlines are expanded to 0d0a, while The remote file, presumably a Unix system likely has just has 0a. I think you'd do best just keeping track of the bytes you've written. DaveA Thank you very much, that worked perfectly. -- http://mail.python.org/mailman/listinfo/python-list
Semaphore Techniques
I'm looking to run a process with a limit of 3 instances, but each execution is over a crontab interval. I've been investigating the threading module and using daemons to limit active thread objects, but I'm not very successful at grasping the documentation. Is it possible to do what I'm trying to do and if so anyone know of a useful example to get started? -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
magicus wrote: On Tue, 28 Jul 2009 16:11:02 +0100, MRAB pyt...@mrabarnett.plus.com wrote: Hendrik van Rooyen wrote: On Monday 27 July 2009 16:49:25 Aahz wrote: In article mailman.3765.1248685391.8015.python-l...@python.org, Hendrik van Rooyen hend...@microcorp.co.za wrote: On Sunday 26 July 2009 21:26:46 David Robinow wrote: I'm a mediocre programmer. Does this mean I should switch to PHP? I have searched, but I can find nothing about this mediocre language. Could you tell us more? :-P (For anyone who is confused by Hendrik's humor, he is saying that David was referring to a programming language named mediocre. English grammar is confusing!) This is true - I intended, when I started the post, to make a crack about how he knew that he was mediocre - If there were some exam or test that you have to pass or fail to be able to make the claim to mediocrity. I was imagining a sort of devil's rating scale for programmers, that could cause one to say things like: I am studying hard so that I can get my mediocre certificate, and one day I hope to reach hacker rank. And then the similarity to I am a COBOL programmer struck me, and I abandoned the ratings. If you were a COBOL programmer, would you want to shout about it? :-) The last time I wrote anything in COBOL was sometime in the early 80s. Somehow that makes me feel good, heh. COBOL: it feels good when you stop. :-) (I was actually referring to the convention of all capitals representing shouting.) -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
On Tue, 28 Jul 2009 23:22:29 +0100, MRAB pyt...@mrabarnett.plus.com wrote: magicus wrote: On Tue, 28 Jul 2009 16:11:02 +0100, MRAB pyt...@mrabarnett.plus.com wrote: Hendrik van Rooyen wrote: On Monday 27 July 2009 16:49:25 Aahz wrote: In article mailman.3765.1248685391.8015.python-l...@python.org, Hendrik van Rooyen hend...@microcorp.co.za wrote: On Sunday 26 July 2009 21:26:46 David Robinow wrote: I'm a mediocre programmer. Does this mean I should switch to PHP? I have searched, but I can find nothing about this mediocre language. Could you tell us more? :-P (For anyone who is confused by Hendrik's humor, he is saying that David was referring to a programming language named mediocre. English grammar is confusing!) This is true - I intended, when I started the post, to make a crack about how he knew that he was mediocre - If there were some exam or test that you have to pass or fail to be able to make the claim to mediocrity. I was imagining a sort of devil's rating scale for programmers, that could cause one to say things like: I am studying hard so that I can get my mediocre certificate, and one day I hope to reach hacker rank. And then the similarity to I am a COBOL programmer struck me, and I abandoned the ratings. If you were a COBOL programmer, would you want to shout about it? :-) The last time I wrote anything in COBOL was sometime in the early 80s. Somehow that makes me feel good, heh. COBOL: it feels good when you stop. :-) It certainly does! (I was actually referring to the convention of all capitals representing shouting.) I rarely shout and I thought that to this day it was still referred to as COBOL. I am still glad that I never pursued a career in dealing w/ such a language. ciao, f -- What you resist, persists. -- http://mail.python.org/mailman/listinfo/python-list
Re: New implementation of re module
MRAB wrote: Hi all, I've been working on a new implementation of the re module. The details are at http://bugs.python.org/issue2636, specifically from http://bugs.python.org/issue2636#msg90954. I've included a .pyd file for Python 2.6 on Windows if you want to try it out. I'm interested in how fast it is generally, compared with the current re module, but especially when faced with those 'pathological' regular expressions which seem to take a long time to finish, for example: re.search(r^(.+|D)*A$, x * 25 + B) which on my PC (1.8GHz) takes 18.98secs with the re module but 0.01secs with this new implementation. I tried this on my 3GHz PC timings pretty much the same. From here http://bugs.python.org/issue1721518 I knocked up this. import time import re import regex s = Add.1, 2020 and Add.1, 2021-2023, 2025, 2028 and 2029 and Add.1) R r = (?:\s|,|and|Add\S*?|Parts?|\([^\)]*\)|[IV\-\d]+)*$ t0 = time.clock() print regex.search(r, s) t1 = time.clock() print time, t1 - t0 print It's going to crash t0 = time.clock() print re.search(r, s) t1 = time.clock() print It hasn't crashed time, t1 - t0 Output shows a slight change in timing:). _regex.RE_Match object at 0x0243A1A0 time 0.00279001940191 It's going to crash _sre.SRE_Match object at 0x024396B0 It hasn't crashed time 98.4238155967 TIA I also got the files bm_regex_effbot.py and bm_regex_v8.py from http://code.google.com/p/unladen-swallow/source/browse/#svn/tests/performance and ran them, then reran them having substituted regex for re. Output timings were roughly effbot re 0.14secs, effbot regex 1.16secs, v8 re 0.17secs and v8 regex 0.67secs. HTH. -- Kindest regards. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: Semaphore Techniques
John D Giotta schrieb: I'm looking to run a process with a limit of 3 instances, but each execution is over a crontab interval. I've been investigating the threading module and using daemons to limit active thread objects, but I'm not very successful at grasping the documentation. Is it possible to do what I'm trying to do and if so anyone know of a useful example to get started? Since you are talking about crontab I assume that you are on an os that supports pthreads. You problem can easily be solved with a named semaphore (see sem_open(3) and sem_overview(7)). Unfortunately Python doesn't expose named semaphores. The multiprocessing library uses named semaphores but you can't set the name yourself. You have to write your own C wrapper or search on pypi and through Google. If you are going to write your own semaphore I highly recommend Cython. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: Semaphore Techniques
On Jul 28, 2009, at 7:19 PM, Christian Heimes wrote: John D Giotta schrieb: I'm looking to run a process with a limit of 3 instances, but each execution is over a crontab interval. I've been investigating the threading module and using daemons to limit active thread objects, but I'm not very successful at grasping the documentation. Is it possible to do what I'm trying to do and if so anyone know of a useful example to get started? Since you are talking about crontab I assume that you are on an os that supports pthreads. You problem can easily be solved with a named semaphore (see sem_open(3) and sem_overview(7)). Unfortunately Python doesn't expose named semaphores. The multiprocessing library uses named semaphores but you can't set the name yourself. You have to write your own C wrapper or search on pypi and through Google. If you are going to write your own semaphore I highly recommend Cython. My POSIX IPC extension permits manipulation of interprocess semaphores: http://semanchuk.com/philip/posix_ipc/ There's also one for SysV IPC: http://semanchuk.com/philip/sysv_ipc/ Enjoy P -- http://mail.python.org/mailman/listinfo/python-list