Pyowa Meeting Tomorrow (8/6)
Pyowa Meeting - Thursday, Aug. 8th, 2009 Time: 6:30 - 8:45 p.m. Location: Ames Public Library, Founders Suite, Ames, IA Itinerary: - Presentation on Building Executables and Installers with GUI2Exe and Inno Setup - Possible group programming exercise - Social Time We hope to see you there! Mike Driscoll www.pyowa.org -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Moovida Media Center 1.0.6 Release
Dear Python users, The Moovida team is happy to announce the release of Moovida Media Center 1.0.6, code-named Jana. Moovida, formerly known as Elisa, is a cross-platform and open-source Media Center written in Python. It uses GStreamer [1] for media playback and pigment [2] to create an appealing and intuitive user interface. This new version fixes many important bugs (see attached release notes) among which crashes on windows (reduced by 35%) and improves the overall performance (the UI is twice as fluid and Moovida uses 10MB less memory). Thanks to contributions from the community, Moovida now ships with complete translations for Spanish, French, Italian, Polish and Brazilian Portuguese. Everyone is welcome to contribute to translate Moovida in their mother tongue: see http://translations.launchpad.net/elisa. This release is a lightweight release, meaning it is pushed through our automatic plugin update system. Additionally a windows installer is available for download on our website. As usual, for users already running Moovida, the upgrade to 1.0.6 should be done automatically via the plugin repository. A complete list of the issues fixed can be found at: http://launchpad.net/elisa/+milestone/1.0.6 This is also summarised in the (attached) release notes. Installers and sources can be downloaded from http://www.moovida.com/download/ Bug reports and feature requests are welcome at http://bugs.launchpad.net/elisa/+filebug Have a media-centered week, Olivier, for the Moovida team [1] http://www.gstreamer.net/ [2] https://code.fluendo.com/pigment/trac Moovida 1.0.6 Jana This is Moovida 1.0.6, sixth release of the 1.0 branch. New features since 1.0.5: - A common caching module in the core Bugs fixed since 1.0.5: - 380974: Widget styles updated too often - 392082: [win:crash] Startup crash when calling __GetProcFromComCtl32 on Acer machines - 401839: [win32] Moovida doesn't start for usernames containing an apostrophe - 259135: [linux] Unable to display pictures served by Coherence over UPnP - 268220: 'Setup LIRC' script crashes after setting up all keys - 293805: [solaris] Moovida doesn't install desktop file - 388910: Picture library is not opening - 396501: Multiple simultaneous loading of the same section - 396510: Unable to login into flickr account - 398541: [win32] FLAC files not recognized - 399384: Tracebacks when entering/scrolling a list controller - 403058: Texts cuts if Liberation font used by Moovida - 408707: Description of track/song going beyond the length of 'textbox' - 254951: The discogs resource provider modifies requests - 274324: Hide passwords in the text entry of the on-screen-keyboard - 296523: Generic favorites plugin depends on the shoutcast plugin - 303307: Invalid frob error from the flickr plugin - 319517: Flickr account cannot be accessed again if once logged out - 390625: Text gets regenerated for widgets not seen on screen - 396948: List widgets don't properly update when deleting or changing items - 400137: moovida 1.0.5. crashes in i18n when no locale is set - 403966: [win32] Removed media sources re-appear - 329849: The man-page is outdated - 399977: HAL plugin should work on Solaris Download You can find source releases of Moovida on the download page: http://www.moovida.com/download Moovida Homepage More details can be found on the project's website: http://www.moovida.com Support and Bugs We use Launchpad for bug reports and feature requests: https://bugs.launchpad.net/elisa/+filebug Developers All code is in a Bazaar branch and can be checked out from there. It is hosted on Launchpad: https://code.launchpad.net/elisa Contributors to this release: - Anna Wojdel - David McLeod - Fernando Casanova Coch - Florian Boucault - Guillaume Emont - Jutta Mailander - Lionel Martin - Loïc Molinari - Maxwell Young - MichaŠSawicz - Olivier Tilloy - Philippe Normand - RafaŠZawadzki - Ugo Riboni - Xose Pérez -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
CVE-2009-0668 and CVE-2009-0669: Releases to fix ZODB ZEO server vulnerabilities
Vulnerabilities have been found in the Zope Object Database (ZODB) Zope Enterprise Objects (ZEO) network protocol that allow: CVE-2009-0668 Arbitrary Python code execution in ZODB ZEO storage servers CVE-2009-0669 Authentication bypass in ZODB ZEO storage servers The vulnerabilities only apply if you are using ZEO to share a database among multiple applications or application instances and if untrusted clients are able to connect to your ZEO servers. The first vulnerability (CVE-2009-0668) was introduced in ZODB 3.3 (Zope 2.8). The second vulnerability (CVE-2009-0669) was introduced in ZODB 3.2 (Zope 2.7). Overview These vulnerabilities are addressed by updates to ZODB. Newer releases of Zope are also being provided for people who get ZODB with Zope releases. A new release of ZODB is available here: http://pypi.python.org/pypi/ZODB3/3.8.2 (There is also a new development release at http://pypi.python.org/pypi/ZODB3/3.9.0b5.) New Zope releases that include the fixes can be found here: http://www.zope.org/Products/Zope/2.10.9 http://www.zope.org/Products/Zope/2.11.4 http://www.zope.org/Products/Zope/2.8.11 http://www.zope.org/Products/Zope/2.9.11 http://www.zope.org/Products/Zope3/3.1.1 http://www.zope.org/Products/Zope3/3.2.4 http://www.zope.org/Products/Zope3/3.3.3 http://www.zope.org/Products/Zope3/3.4.1 We recommend updating any ZEO storoage servers you're running to ZODB 3.8.2 (or ZODB 3.9.0b5) or to ZODB software provided with the Zope releases listed above. These versions support ZEO clients as old as ZODB 3.2. It isn't necessary to update client software (such as Zope application servers). Restricting access to ZEO storage servers It is very important to restrict write access to ZODB databases. These releases only protect against vulnerabilities in the ZEO network protocol. ZODB uses Python pickles to store data. Loading data from the database can cause arbitrary code to be executed as part of object deserialization. Clients have full access to manipulate database data. For this reason, it is very important that only trusted clients be allowed to write to ZODB databases. Jim -- Jim Fulton -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: access read / write violation with ctypes
DH wrote: snip I'm using popen to capture dcraw stdout and want to pass it to magickwand. If I instead write the dcraw output to a file then read it with magickwand I get the same error. But if I comment out the dcraw protion and read the dcraw output file from the previous attempt, MagickWand opens the file fine and I can manipulate it to my hearts content. The basics: snip Just a quick guess, based only on this paragraph. But I'd guess the dcraw output file is buffered, and is not fully written when you're trying to read it back. You could do some checking by comparing sizes, when you get it from the pipe, and when you see it finally written in the directory. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Datetime with float seconds
On Wednesday 05 August 2009 14:50:04 kpal wrote: Hello Everybody, The standard datetime has 1 microsecond granularity. My application needs finer time resolution, preferably float seconds. Is there an alternative to the out-of-the-box datetime? Timezone support is not essential. I am curious as to what would require less than microsecond timing - about the only thing I can think of would be something involving measuring the speed of light, where nanoseconds or better would be nice. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: Parsing Binary Structures; Is there a better way / What is your way?
Paul Rubin wrote: Martin P. Hellwig martin.hell...@dcuktec.org writes: Is there an advantage using shifts and masks over my kitchen type solution? Weren't you complaining about the 8-to-1 expansion from turning each bit to an ascii char? One warning to Martin: If you want your code portable across systems, watch out for big-endian/little-endian issues, as well as alignment ones. Shift mask code tends to be highly specific to a particular endian-ness, especially if trying to get multiple bits that cross a byte or word boundary. Over the years, I know I've seen at least three endian versions for the same 32bit word. Something like abcd, dcba, and cdab. One advantage of converting first to bitstrings, is that there's just the two places to fix, for portability, the conversion from byte array to bitstring, and the conversion back. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: os.system in a service
Gabriel Genellina schrieb: En Wed, 05 Aug 2009 13:07:39 -0300, Lawrence Wong lawrence...@hotmail.com escribió: I wrote a program which runs a .bat file using os.system like: 'os.system(pathToBatFile)' and everything was good. Then I decided to turn my program into a service as opposed to being run with the command prompt showing. When my program became a service, I noticed that the os.system command to run my .bat file was no longer working. By 'not working' I mean no exception is thrown, but it was as if the line with os.system(pathToBatFile) did not exist. I was wondering why this is and if there is a way to fix this or what an alternative to using os.system to run my .bat file was? Capture stdout and stderr and you'll probably see the error message: some_command logfile.txt 21 Which isn't possible as a service. The OP might consider using suprocess istead of os.system, and establish pipes to read the output of the command into a file he can analyze. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing Binary Structures; Is there a better way / What is your way?
On Wednesday 05 August 2009 16:46:13 Martin P. Hellwig wrote: Hi List, On several occasions I have needed (and build) a parser that reads a binary piece of data with custom structure. For example (bogus one): BE +-+-+-+-+--++ | Version | Command | Instruction | Data Length | Data | Filler | +-+-+-+-+--++ Version: 6 bits Command: 4 bits Instruction: 5 bits Data Length: 5 bits Data: 0-31 bits Filler: filling 0 bits to make the packet dividable by 8 what I usually do is read the packet in binary mode, convert the output to a concatenated 'binary string'(i.e. '0101011000110') and then use slice indeces to get the right data portions. Depending on what I need to do with these portions I convert them to whatever is handy (usually an integer). This bit banging stuff is a PITA, no matter what you do. Python does not have bit fields like C. And C bit fields are implementation dependent. Write an extension? Some time ago I asked a similar question, and Castironpi came up with what was essentially an indexed integer, with named bits. It stores the bits natively, but I suspect that the price paid is access time. I enclose a module that you can adapt. It talks about bytes but they are integers really. It is different from what you are doing, as it was aimed at reading and writing bits in a hardware context. If you get your head around the concept, then it may give you some ideas. It should be possible to extend the concept to pass name,length tuples at construction time instead of just a name with an implied length of one bit, and it may make sense to change the underlying type from an integer to an array of one byte integers. It is nice to be able to say: val = bitname() to read, and bitname(1) or bitname(0) to write. I can also write: outputbits[3] = 1 or val = inputbits[5] If you can successfully generalise it to field names It should be very useful. I cannot think of a way though, to not have the in and out split, but you can program your way around that - you do not have to update in place. - Hendrik bits.py Description: application/python -- http://mail.python.org/mailman/listinfo/python-list
How to comment on a Python PEP?
Is there a mechanism for submitting comments on a Python PEP? -- View this message in context: http://www.nabble.com/How-to-comment-on-a-Python-PEP--tp24840417p24840417.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Datetime with float seconds
On Aug 6, 7:43 am, Hendrik van Rooyen hend...@microcorp.co.za wrote: I am curious as to what would require less than microsecond timing - about the only thing I can think of would be something involving measuring the speed of light, where nanoseconds or better would be nice. You are right :-) I am trying to write a scientific software that does some satellite geodesy computations (involving the speed of light), and I would prefer to keep all the times float, while retaining the time and time interval arithmetics and format transformation capabilities of datetime. The system time granularity, that is of cause limited, is not a problem at all, as the data are to be initialized by constructing instances from external data. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing Binary Structures; Is there a better way / What is your way?
On Wednesday 05 August 2009 20:12:05 Paul Rubin wrote: Martin P. Hellwig martin.hell...@dcuktec.org writes: what I usually do is read the packet in binary mode, convert the output to a concatenated 'binary string'(i.e. '0101011000110') and Something wrong with reading the data words as an integer and using old fashioned shifts and masks to get at the bit fields? There is nothing wrong with that, and in the final analysis, it is what is used - however, I can sympathize with the OP, as it is much nicer to just call a named thing than to juggle a bunch of hard coded shifts and masks. I think the real point here is sort of meta programming - what is needed is a way to describe and name the elements of the structure so that useful python objects are created. The code I posted for bits does that, and I use it all the time - it is almost as good as being back in 8031 assembler with direct named bit access. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing Binary Structures; Is there a better way / What is your way?
On Wednesday 05 August 2009 21:41:26 Martin P. Hellwig wrote: Yes you are (of course) right, my 'dream' solution would be something that accepts slice indeces on bit level. Your reasoning did reveal some flaws in my approach though ;-) This is the first time I have been compared to the sandman... :-) - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: merge two png pic
On Thu, Aug 6, 2009 at 12:17 PM, cocobear cocobear...@gmail.com wrote: I want to view image use Windows Pic View. If you run out of memory trying to combining those images into a 30k by 40k pixels image, the Windows Pic View isn't going to be able to display it either. Regards, Ching-Yun Xavier Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Subclassing Python's dict
On Thu, Aug 6, 2009 at 1:19 PM, alex23 wuwe...@gmail.com wrote: Xavier Ho wrote: You should subclass collections.UserDict, and not the default dict class. Refer to the collections module. Xavier, why do you think that is the correct approach? I'll be honest first and say that I do not completely understand how dict is implemented in the underlying C structure. But as Bruno had already mentioned, dict has a slightly different behaviour then we'd expect. For example, the __getitem__() function isn't actually used by the interpreter (which, you know, *can* be a problem.) http://www.python.org/download/releases/2.2.3/descrintro/#subclassing (I don't know if 2.6.2 changed anything since 2.2.3, but there are some references you can look at, and sample code.) To answer your question, it's really not the correct approach, but I think (meaning: untested) UserDict doesn't have the same implementation, which might free up some restrictions Sergey encountered. The docs say The need for this class has been largely supplanted by the ability to subclass directly from dict (a feature that became available starting with Python version 2.2). I didn't realise they took UserDict out in later versions (2.6, for example), and put it back in Python 3.0. Does anyone know why? So, I do not actually know. If you mean that Sergey should subclass _in this instance_ could you please explain why? (Sorry if you already have, I never saw your original post...) It was really more or less an educated guess. He didn't tell us what he is trying to achieve, so _in this instance_ I can't give more advice than saying well, if this doesn't work, here are you other options that I know of/just found. Try these and let us know if you got it to work. *winks* - Sometimes I do answer a little too quickly, I apologise for that. - Xav -- http://mail.python.org/mailman/listinfo/python-list
Re: String to valid Python identifier
Is there any easy function in the stdlib to convert any random string in a valid Python identifier .. possibly by replacing non-valid characters with _ ? I think this is fairly underspecified as a problem statement. A solution that would meet your specification would be def mkident(s): return foo It returns a valid Python identifier for any random string. If you now complain that this gives too many collisions, I propose def mkident(s): return foo%d % (hash(s) 0x7fff) Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: remove last 76 letters from string
print nucleotides, seq[-76] last_part = line.rstrip()[-76 : ] You all mean: seq[:-76] , right? (assuming you've already stripped any junk off the end of the string) Iain -- http://mail.python.org/mailman/listinfo/python-list
Re: os.system in a service
En Thu, 06 Aug 2009 03:59:13 -0300, Diez B. Roggisch de...@nospam.web.de escribió: Gabriel Genellina schrieb: En Wed, 05 Aug 2009 13:07:39 -0300, Lawrence Wong lawrence...@hotmail.com escribió: I wrote a program which runs a .bat file using os.system like: 'os.system(pathToBatFile)' and everything was good. Then I decided to turn my program into a service as opposed to being run with the command prompt showing. When my program became a service, I noticed that the os.system command to run my .bat file was no longer working. [...] Capture stdout and stderr and you'll probably see the error message: some_command logfile.txt 21 Which isn't possible as a service. Why you say so? One should avoid using mapped drive letters and network shares -- that probably aren't defined for the account under which the service runs. And always use absolute paths. And ensure the account has write permissions for the output file... But other than that, os.system should work fine. Do I miss something? The OP might consider using suprocess istead of os.system, and establish pipes to read the output of the command into a file he can analyze. That's a good idea, although overkill for simple cases I'd say. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: remove last 76 letters from string
On Thu, Aug 6, 2009 at 6:28 PM, Iain King iaink...@gmail.com wrote: print nucleotides, seq[-76] last_part = line.rstrip()[-76 : ] You all mean: seq[:-76] , right? (assuming you've already stripped any junk off the end of the string) I think so, probably both of them typo'd. (What are the probabilities of that?) It looks to me like you have two lines per DNA sequence. What you could do instead, is to alternate the line reading with a with statement, as suggested by Jan. Although I don't know why he's nesting two of them. (explanation would be neat.) Here's my version of approach, given the sample data the OP posted: with open('NodeList.txt', 'r') as file: for line in file.readlines(): line = line.rstrip() if line[0] == '': # Do for New DNA Sequence # ... else: line = line[:-76] # ... Should do what you need. Best regards, Ching-Yun Xavier Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing Binary Structures; Is there a better way / What is your way?
On Aug 5, 3:46 pm, Martin P. Hellwig martin.hell...@dcuktec.org wrote: Hi List, On several occasions I have needed (and build) a parser that reads a binary piece of data with custom structure. For example (bogus one): BE +-+-+-+-+--++ | Version | Command | Instruction | Data Length | Data | Filler | +-+-+-+-+--++ Version: 6 bits Command: 4 bits Instruction: 5 bits Data Length: 5 bits Data: 0-31 bits Filler: filling 0 bits to make the packet dividable by 8 what I usually do is read the packet in binary mode, convert the output to a concatenated 'binary string'(i.e. '0101011000110') and then use slice indeces to get the right data portions. Depending on what I need to do with these portions I convert them to whatever is handy (usually an integer). This works out fine for me. Most of the time I also put the ASCII art diagram of this 'protocol' as a comment in the code, making it more readable/understandable. Though there are a couple of things that bothers me with my approach: - This seems such a general problem that I think that there must be already a general pythonic solution. - Using a string for binary representation takes at least 8 times more memory for the packet than strictly necessary. - Seems to need a lot of prep work before doing the actual parsing. Any suggestion is greatly appreciated. -- MPHhttp://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' Take a look at the bitstring module (in pypi or google code). It's designed to help make this sort of thing easy and it's more fully featured than BitVector or BitSet. Internally the data is stored as a byte array, so memory isn't wasted. It will also do all the dirty work of bit masking and shifting so that you can concentrate on the real problems. For example: s = BitString('0x1232432312') # just to give us some data to play with ver, comm, instr, bitlen = s.read('uint6, bin4, bin5, uint5') data = s.readbits(bitlen) Different interpretations of the binary data are given using Python properties (e.g. s.hex, s.oct, s.uint, etc.) and it supports bit-wise slicing, modification, finding, replacing and more. It is also still in active development (full disclosure: I'm the author :-)). -- http://mail.python.org/mailman/listinfo/python-list
Re: How to comment on a Python PEP?
Is there a mechanism for submitting comments on a Python PEP? You post to python-dev or comp.lang.python, and you CC the author. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
handling kill signal
I want to handle a kill signal..In my program i wrote like this def handler(signum, frame): print Signal,signum delete_temp_file() exit(1) signal.signal(signal.SIGTERM, handler) And when i tried pkill processid .program is exited but not deleting the temp file -- http://mail.python.org/mailman/listinfo/python-list
Re: remove last 76 letters from string
Iain King wrote: print nucleotides, seq[-76] last_part = line.rstrip()[-76 : ] You all mean: seq[:-76] , right? (assuming you've already stripped any junk off the end of the string) The OP said cut out the last 76 letters (nucleotides) from each individual sequence and send them to a new txt file with a similar format., ie extract the last 76 letters (in the same format) to a file. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem in installing PyGreSQL
I have downloaded the psycopg2 tar file from the following link. http://initd.org/tracker/psycopg I have done the following things. * Extracting the files from the tar file * tried to execute python ./setup.py build It gives the following error. #python ./setup.py build running build running build_py running build_ext Traceback (most recent call last): File ./setup.py, line 410, in ? ext_modules=ext) File distutils/core.py, line 149, in setup File distutils/dist.py, line 946, in run_commands File distutils/dist.py, line 966, in run_command File distutils/command/build.py, line 112, in run File /usr/lib/python2.4/cmd.py, line 333, in run_command del help[cmd] File distutils/dist.py, line 965, in run_command File /usr/lib/python2.4/cmd.py, line 117, in ensure_finalized pass File ./setup.py, line 219, in finalize_options except (Warning, w): NameError: global name 'w' is not defined What would be the solution? Otherwise can you tell how to install DB-API in debian machine. On Wed, Aug 5, 2009 at 10:43 AM, Dennis Lee Bieber wlfr...@ix.netcom.comwrote: On Tue, 4 Aug 2009 09:55:47 -0400, D'Arcy J.M. Cain da...@druid.net declaimed the following in gmane.comp.python.general: By the way, you don't have to be super user to install PyGreSQL. You just need SU if you want to install it system wide. PyGreSQL doesn't require any special privileges to run. Potentially silly question: While the DB-API module may be installable in a user mode... Do we know if the original querant even has PostgreSQL running and accessible? The statement OP I want to access the database related stuffs in python.So I found the OP PyGreSQL module in net. doesn't leave me with any confidence that they realize this is just an access module for one specific server -- and that they still need a server to which they can connect. If they don't have a PostgreSQL server, it may be better just to direct them to SQLite3... -- WulfraedDennis Lee Bieber KD6MOG wlfr...@ix.netcom.com wulfr...@bestiaria.com HTTP://wlfraed.home.netcom.com/ (Bestiaria Support Staff: web-a...@bestiaria.com) HTTP://www.bestiaria.com/ -- http://mail.python.org/mailman/listinfo/python-list -- Regards, Thangappan.M -- http://mail.python.org/mailman/listinfo/python-list
Cython + setuptools not working with .pyx,only with .c-files
Hi, I'm trying to build a Cython-extension as Egg. However, this doesn't work - I can either use distutils to build the extension, creating a myextension.c-file on the way. If that's there, I can use setuptools to build the egg. But when I remove the .c-file, the .pyx-file isn't used to re-generate it. This is my setup.py: import os import glob from setuptools import setup, Extension #from distutils.core import setup #from distutils.extension import Extension from Cython.Distutils import build_ext objs = [...] # a static lib I want to wrap setup( name='MyExtension', version=0.1, description='', author='Diez B. Roggisch', author_email='...', cmdclass = {'build_ext': build_ext}, ext_modules = [Extension(myextension, [myextension.pyx], libraries=[crypto], extra_objects = objs)], - I can of course check in the myextension.c-file , and then when actually working on the extension create it new by uncommenting the above lines. But I guess that's not really the way things should work... Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Subclassing Python's dict
On Aug 5, 7:39 am, Bruno Desthuilliers bruno. 42.desthuilli...@websiteburo.invalid wrote: Sergey Simonenko a écrit : Hi, I subclass builtin 'dict' in my application and experience some problems with it. The whole issue is that I should redefine 'setdefault' and 'update' methods after redefining '__setitem__' or/and '__delitem__', otherwise 'update' and 'setdefault' ignore redefined '__setitem__' and use builtin dict's one so dict looks kinda like a black box. Another guy have reported me that he experiences similar problems with subclassing builtin 'list'. I indeed notice this behaviour here (Python 2.6.2). I'm afraid it has to do with some optimization tricks (dict being the very fundamental data structure in Python, it has to be higly optimized). You can ultimately blame it on optimization in this case, but in general there isn't any way (in Python) to require that __setitem__ be the common point for all modifications. In fact this is an example of a general condition of OOP. A high- level method may or may not call a low-level method to do its dirty work, and there is no way to know this simply from the class's interface. You need to have knowledge of the implementation to know whether you need to override high-level or low-level methods. In general you can't safely subclass based on the interface alone; you have to know what you're subclassing. (As an aside: this intuitively is the reason why I never cared much for some of the arguments against inheritance. Many arguments against inheritance go like this: Inheritance is bad because X can happen if you're not careful. Doesn't mean anything to me because you have be careful anyway.) Because of the care required when subclassing, I tend to use inheritance only when the intended base class is A. also under my control, or B. specifically designed to be subclassed. Examples of B in the standard Python library are Queue and Thread. list and dict are allowed to be subclassed but aren't specifically designed for it, so I tend not to subclass those. (It is occasionally indispensible, though.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Python to automate builds
On Thu, Aug 6, 2009 at 12:39 AM, Kostakosta.koe...@gmail.com wrote: Setenv.bat sets up the path and other environment variables build.exe needs to compile and link (and even binplace) its utilities. So building itself is not the issue. The problem is that if I call setenv.bat from Python and then build.exe, but the modifications to the path (and other environment settings) are not seen by Python, so the attempt to build without a specified path fails. It sounds like you do not propagate the environment when calling setenv.bat from python. There is an option to do so in subprocess.Popen init method, or you can define your own environment if you do not want to propagate the whole environment (but this is often difficult to avoid for build environment in my experience, expecially if you don't have access to the sources of the whole system to check which variables are necessary). David -- http://mail.python.org/mailman/listinfo/python-list
RE: os.system in a service
I actually found the solution. I was trying to copy a file from another computer to the current one. My 'access was denied'. So I had to go to my service at Admin Tools -- Services and 'Log on as' the Administrator. Was ok after that. Thanks for your responses everyone. To: python-list@python.org From: gagsl-...@yahoo.com.ar Subject: Re: os.system in a service Date: Thu, 6 Aug 2009 05:35:57 -0300 En Thu, 06 Aug 2009 03:59:13 -0300, Diez B. Roggisch de...@nospam.web.de escribió: Gabriel Genellina schrieb: En Wed, 05 Aug 2009 13:07:39 -0300, Lawrence Wong lawrence...@hotmail.com escribió: I wrote a program which runs a .bat file using os.system like: 'os.system(pathToBatFile)' and everything was good. Then I decided to turn my program into a service as opposed to being run with the command prompt showing. When my program became a service, I noticed that the os.system command to run my .bat file was no longer working. [...] Capture stdout and stderr and you'll probably see the error message: some_command logfile.txt 21 Which isn't possible as a service. Why you say so? One should avoid using mapped drive letters and network shares -- that probably aren't defined for the account under which the service runs. And always use absolute paths. And ensure the account has write permissions for the output file... But other than that, os.system should work fine. Do I miss something? The OP might consider using suprocess istead of os.system, and establish pipes to read the output of the command into a file he can analyze. That's a good idea, although overkill for simple cases I'd say. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list _ More storage. Better anti-spam and antivirus protection. Hotmail makes it simple. http://go.microsoft.com/?linkid=9671357-- http://mail.python.org/mailman/listinfo/python-list
Re: Cython + setuptools not working with .pyx,only with .c-files
On Thu, Aug 6, 2009 at 7:38 PM, Diez B. Roggischde...@nospam.web.de wrote: Hi, I'm trying to build a Cython-extension as Egg. However, this doesn't work - I can either use distutils to build the extension, creating a myextension.c-file on the way. If that's there, I can use setuptools to build the egg. But when I remove the .c-file, the .pyx-file isn't used to re-generate it. This is my setup.py: import os import glob from setuptools import setup, Extension #from distutils.core import setup #from distutils.extension import Extension from Cython.Distutils import build_ext What happens if you import setuptools *after* Cython.distutils ? My guess - I could be wrong - is that both Cython.distutils and setuptools monkey-patch distutils, and that setuptools does not see Cython.Distutils. It could also be an incompatibility between Cython.Distutils and setuptools (the design of distutils forces you to take into account the details of things modified by every distutils extension). cheers, David -- http://mail.python.org/mailman/listinfo/python-list
inspect.stack() performance
I use inspect.stack() to extract some info, such as file name, function name and line number, for the sake of logging (home brew logger). I tested to see how much time it takes to execute the command: Python 2.4.3 (#1, Jan 21 2009, 01:11:33) [GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2 Type help, copyright, credits or license for more information. import timeit t = timeit.Timer('inspect.stack()', 'import inspect') t.repeat(3,1000) [0.28500604629516602, 0.28315305709838867, 0.29169297218322754] About 280uSec per call. If I log 1000 times per seconds than I get to spend 28% of the process time on inspect.stack() Is there a better/quicker way of retrieving the same info? Thanks, --doron -- http://mail.python.org/mailman/listinfo/python-list
one method of COM object needs a variant type variable
How i can use this type in win32.com? One method of com object (geomedia storage service) needs this variable for storage geometry of geometry object (this variable will be writen into blob in DB). Is possible make this variable in py?? Thanks Jelen/Stack -- http://mail.python.org/mailman/listinfo/python-list
Re: Overlap in python
On 8/5/2009 10:56 AM, nn wrote: On Aug 5, 7:13 am, Marcus Wanner marc...@cox.net wrote: On 8/4/2009 6:09 PM, MRAB wrote: parts = [(5, 9, a), (7, 10, b), (3, 6, c), (15, 20, d), (18, 23, e)] parts.sort() parts [(3, 6, 'c'), (5, 9, 'a'), (7, 10, 'b'), (15, 20, 'd'), (18, 23, 'e')] # Merge overlapping intervals. pos = 1 while pos len(parts): # Merge the pair in parts[pos - 1 : pos + 1] if they overlap. p, q = parts[pos - 1 : pos + 1] if p[1] = q[0]: parts[pos - 1 : pos + 1] = [(p[0], max(p[1], q[1]), p[2] + . + q[2])] else: # They don't overlap, so try the next pair. pos += 1 parts [(3, 10, 'c.a.b'), (15, 23, 'd.e')] That's the best solution I've seen so far. It even has input/output formatted as close as is reasonably possible to the format specified. As we would say in googlecode, +1. Marcus How does it compare to this one? http://groups.google.com/group/comp.lang.python/browse_frm/thread/1a1d2ed9d05d11d0/56684b795fc527cc#56684b795fc527cc That is a different problem, and the solution is more complex. I am not going to try to judge which is better. Marcus -- print ''.join([chr(((ord(z)+(ord(I'M/THE[3])+sum( [ord(x)for x in 'CRYPTOR'])))%(4*ord('8')+ord( ' ' for z in ''.join(([(('\xca\x10\x03\t'+ '\x01\xff\xe6\xbe\x0c\r\x06\x12\x17\xee\xbe'+ '\x10\x03\x06\x12\r\x0c\xdf\xbe\x12\x11\x13'+ '\xe8')[13*2-y]) for y in range(int(6.5*4)+1)] ))]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python docs disappointing - group effort to hire writers?
RayS wrote: At 08:35 PM 8/5/2009 -0700, r wrote: ... Any real sense of community is undermined -- or even destroyed -- to be replaced by virtual equivalents that strive, unsuccessfully, to synthesize a sense of community. I've brought up the idea of the quasi-community doc that PHP uses to good effect. And what have you done about setting up such a project? http://www.php.net/manual/en/language.types.array.php is a prime example where 2/3 of the doc is user-contributed comments and code. I consider consider this to an unreadable mishmash. If you and others want something like that, do it. And quite bitching about the work of those of us who have done something compact and readable. We are all volunteers here. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: remove last 76 letters from string
On Aug 6, 11:34 am, MRAB pyt...@mrabarnett.plus.com wrote: Iain King wrote: print nucleotides, seq[-76] last_part = line.rstrip()[-76 : ] You all mean: seq[:-76] , right? (assuming you've already stripped any junk off the end of the string) The OP said cut out the last 76 letters (nucleotides) from each individual sequence and send them to a new txt file with a similar format., ie extract the last 76 letters (in the same format) to a file. So he did. Excuse me while I go eat my other foot. -- http://mail.python.org/mailman/listinfo/python-list
Re: unicode() vs. s.decode()
On Thu, 2009-08-06 at 01:31 +, John Machin wrote: Faster by an enormous margin; attributing this to the cost of attribute lookup seems implausible. Ok, fair point. I don't think the time difference fully registered when I composed that message. Testing a global access (LOAD_GLOBAL) versus an attribute access on a global object (LOAD_GLOBAL + LOAD_ATTR) shows that the latter is about 40% slower than the former. So that certainly doesn't account for the difference. Suggested further avenues of investigation: (1) Try the timing again with cp1252 and utf8 and utf_8 (2) grep utf-8 Python2.X_source_code/Objects/unicodeobject.c Very pedagogical of you. :) Indeed, it looks like bigger player in the performance difference is the fact that the code path for unicode(s, enc) short-circuits the codec registry for common encodings (which includes 'utf-8' specifically), whereas s.decode('utf-8') necessarily consults the codec registry. Cheers, Jason. -- http://mail.python.org/mailman/listinfo/python-list
Re: unicode() vs. s.decode()
* Michael Ströder (Wed, 05 Aug 2009 16:43:09 +0200) These both expressions are equivalent but which is faster or should be used for any reason? u = unicode(s,'utf-8') u = s.decode('utf-8') # looks nicer decode was added in Python 2.2 for the sake of symmetry to encode(). It's essentially the same as unicode() and I wouldn't be surprised if it is exactly the same. I don't think any measurable speed increase will be noticeable between those two. Thorsten -- http://mail.python.org/mailman/listinfo/python-list
Re: Python docs disappointing - group effort to hire writers?
On Aug 6, 2009, at 6:55 AM, Terry Reedy wrote: RayS wrote: At 08:35 PM 8/5/2009 -0700, r wrote: ... Any real sense of community is undermined -- or even destroyed -- to be replaced by virtual equivalents that strive, unsuccessfully, to synthesize a sense of community. I've brought up the idea of the quasi-community doc that PHP uses to good effect. And what have you done about setting up such a project? http://www.php.net/manual/en/language.types.array.php is a prime example where 2/3 of the doc is user-contributed comments and code. I consider consider this to an unreadable mishmash. If you and others want something like that, do it. And quite bitching about the work of those of us who have done something compact and readable. We are all volunteers here. As I struggle through trying to figure out how to make python do simple stuff for me, I frequently generate samples. If some volunteer here would point me towards the documentation that would tell me how I can alter the existing Python docs to include sample code, I'd be more than happy to do so. I would like to do it. Please point me to the docs that tell me how to do it so that we people with newbie questions and a need for examples can get out of your way and do it ourselves. Thanks, Kee Nethery -- http://mail.python.org/mailman/listinfo/python-list
ANN: Python for Bioinformatics book
Python for Bioinformatics ISBN 1584889292 Amazon: http://www.tinyurl.com/biopython Publisher: http://www.crcpress.com/product/isbn/9781584889298 This book introduces programming concepts to life science researchers, bioinformaticians, support staff, students, and everyone who is interested in applying programming to solve biologically-related problems. Python is the chosen programming language for this task because it is both powerful and easy-to-use. It begins with the basic aspects of the language (like data types and control structures) up to essential skills on today's bioinformatics tasks like building web applications, using relational database management systems, XML and version control. There is a chapter devoted to Biopython (www.biopython.org) since it can be used for most of the tasks related to bioinformatics data processing. There is a section with applications with source code, featuring sequence manipulation, filtering vector contamination, calculating DNA melting temperature, parsing a genbank file, inferring splicing sites, and more. There are questions at the end of every chapter and odd numbered questiona are answered in an appendix making this text suitable for classroom use. This book can be used also as a reference material as it includes Richard Gruet's Python Quick Reference, and the Python Style Guide. DVD: The included DVD features a virtual machine with a special edition of DNALinux, with all the programs and complementary files required to run the scripts commented in the book. All scripts can be tweaked to fit a particular configuration. By using a pre-configured virtual machine the reader has access to the same development environment than the author, so he can focus on learning Python. All code is also available at the http://py3.us/## where ## is the code number, for example: http://py3.us/57 I've been working on this book for more than two years testing the examples under different setups and working to make the code compatible for most versions of Python, Biopython and operating systems. Where there is code that only works with a particular dependency, this is clearly noted. Finally, I want to highlight that non-bioinformaticians out there can use this book as an introduction to bioinformatics by starting with the included Diving into the Gene Pool with BioPython (by Zachary Voase and published originally in Python Magazine). -- Sebastián Bassi. Diplomado en Ciencia y Tecnología. Non standard disclaimer: READ CAREFULLY. By reading this email, you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (BOGUS AGREEMENTS) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer. -- http://mail.python.org/mailman/listinfo/python-list
Help making this script better
Hi, After much Google searching and trial error, I was able to write a Python script that posts XML files to a REST API using HTTPS and passing PEM cert key file. It seems to be working but would like some pointers on how to handle errors. I am using Python 2.4, I don't have the capability to upgrade even though I would like to. I am very new to Python so help will be greatly appreciated and I hope others can use this script. #!/usr/bin/python # # catalog_feeder.py # # This sciript will process a directory of XML files and push them to the Enterprise Catalog. # You configure this script by using a configuration file that describes the required variables. # The path to this file is either passed into the script as a command line argument or hard coded # in the script. The script will terminate with an error if it can't process the XML file. # # IMPORT STATEMENTS import httplib import mimetypes import os import sys import shutil import time from urllib import * from time import strftime from xml.dom import minidom def main(c): start_time = time.time() # Set configuration parameters try: # Process the XML conf file xmldoc = minidom.parse(c) catalog_host = readConfFile(xmldoc, 'catalog_host') catalog_port = int(readConfFile(xmldoc, 'catalog_port')) catalog_path = readConfFile(xmldoc, 'catalog_path') collection_name = readConfFile(xmldoc, 'collection_name') cert_file = readConfFile(xmldoc, 'cert_file') key_file = readConfFile(xmldoc, 'key_file') log_file = readConfFile(xmldoc, 'log_file') input_dir = readConfFile(xmldoc, 'input_dir') archive_dir = readConfFile(xmldoc, 'archive_dir') hold_dir = readConfFile(xmldoc, 'hold_dir') except Exception, inst: # I had an error so report it and exit script print Unexpected error opening %s: %s % (c, inst) sys.exit(1) # Log Starting logOut = verifyLogging(log_file) if logOut: log(logOut, Processing Started ...) # Get list of XML files to process if os.path.exists(input_dir): files = getFiles2Post(input_dir) else: if logOut: log(logOut, WARNING!!! Couldn't find input directory: + input_dir) cleanup(logOut) else: print Dir doen't exist: + input_dir sys.exit(1) try: # Process each file to the catalog connection = httplib.HTTPSConnection(catalog_host, catalog_port, key_file, cert_file) for file in files: log(logOut, Processing + file + ...) try: response = post2Catalog(connection, catalog_path, os.path.join (input_dir, file), collection_name) if response.status == 200: msg = Succesfully posted + file + to cataloge ... print msg log(logOut, msg) # Move file to done directory shutil.move(os.path.join(input_dir, file), os.path.join (archive_dir, file)) else: msg = Error posting + file + to cataloge [ + response.read () + ] ... print msg log(logOut, response.read()) # Move file to error dir shutil.move(os.path.join(input_dir, file), os.path.join(hold_dir, file)) except IOError, (errno): print %s % (errno) except httplib.HTTPException, (e): print Unexpected error %s % (e) run_time = time.time() - start_time print 'Run time: %f seconds' % run_time # Clean up connection.close() cleanup(logOut) # Get an arry of files from the input_dir def getFiles2Post(d): return (os.listdir(d)) # Read out the conf file and set the needed global variable def readConfFile(xmldoc, tag): return (xmldoc.getElementsByTagName(tag)[0].firstChild.data) # Write out the message to log file def log(f, m): f.write(strftime(%Y-%m-%d %H:%M:%S) + : + m + '\n') # Clean up and exit def cleanup(logOut): if logOut: log(logOut, Processing Ended ...\n)
Re: ANN: Python for Bioinformatics book
Sebastian Bassi: All code is also available at thehttp://py3.us/##where ## is the code number, for example:http://py3.us/57 The book looks interesting, but that doesn't look like a good way to show/offer the code. I suggest to also put it into a zip that can be downloaded. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Python for Bioinformatics book
On Thu, Aug 6, 2009 at 11:52 AM, Bearophilebearophileh...@lycos.com wrote: The book looks interesting, but that doesn't look like a good way to show/offer the code. I suggest to also put it into a zip that can be downloaded. Code is also in a directory in the DVD and also inside the virtual machine. Anyway I think it wouldn't hurt to make a zip and put it online, so i will do it. Thanks. Best, SB. -- http://mail.python.org/mailman/listinfo/python-list
Help with regex
Hey guys, I'm creating a python script that is going to try to search a text file for any text that matches my regular expression. The thing it is looking for is: FILEVERSION #,#,#,# The # symbol represents any number that can be any length 1 or greater. Example: FILEVERSION 1,45,10082,3 The regex should only match the exact above. So far here's what I have come up with: re.compile( r'FILEVERSION (?:[0-9]+\,){3}[0-9]+' ) This works, but I was hoping for something a bit cleaner. I'm having to create a special case portion of the regex for the last of the 4 numbers simply because it doesn't end with a comma like the first 3. Is there a better, more compact, way to write this regex? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python configuration question when python scripts are executed using Appweb as web server.
Hi Gabriel On Aug 5, 4:18 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Tue, 04 Aug 2009 10:15:24 -0300, IronyOfLife mydevfor...@gmail.com escribió: On Aug 3, 8:42 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Mon, 03 Aug 2009 11:04:07 -0300, IronyOfLife mydevfor...@gmail.com escribió: I have installed python 2.6.2 in windows xp professional machine. I have set the following environment variables -- PYTHONPATH. It points to following windows folders: python root folder, the lib folder and lib-tk folder. Why? Did you read it somewhere? Usually there is no need to set the PYTHONPATH variable at all; remove it. Setting PYTHONPATH environment variables is mentioned in Python docs. Could you provide a link please? Setting PYTHONPATH should not be Here are couple of links that discusses setting PYTHONPATH environment variable. http://docs.python.org/using/windows.html http://www.daimi.au.dk/~chili/PBI/pythonpath.html necesary, and in fact it's a very bad idea. Environment variables are global, but Python modules may depend on the Python version, architecture, install location... By example, you may install a 64 bits Python 3.1 version *and* a 32 bits Python 2.5 version and they both can coexist peacefully - but an extension module compiled for the former cannot be used in the later version. You must build a separate library for each version, and install them in two separate directories. But since the PYTHONPATH variable is shared by all installations, which directory should contain? It's best not to use PYTHONPATH at all and rely on other alternatives (like .pth files, that are searched relative to the current Python executable, so different versions use different configuration files) I understand your concerns regarding setting of PYTHONPATH while multiple versions of Python are installed on the same machine. My fix however does not use PYTHONPATH. The GNUTLS wrapper module for PYTHON loads the GNUTLS dll's and it was not able to find them. Using FileMon (win tool) I found out the paths that are scanned and I copied the dlls to one of such paths. I still do not like this fix. This is a temporary solution. Can you explain maybe with some sample how to set .pth files? Maybe this will resolve my issue. I solved the issue temporarily by copying the gnutls related dlls to the path searched by python.exe Glad to see you could finally fix it! -- Gabriel Genellina Thanks very much for your reply. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python docs disappointing - group effort to hire writers?
Kee Nethery wrote: As I struggle through trying to figure out how to make python do simple stuff for me, I frequently generate samples. If some volunteer here would point me towards the documentation that would tell me how I can alter the existing Python docs to include sample code, I'd be more than happy to do so. No offence, but the last thing the official documentation needs is example code written by people learning how to code. Suggest changes, request clarifications, submit samples for review, sure, but direct modification by users? I've seen the PHP docs; thanks but no thanks. I would like to do it. Please point me to the docs that tell me how to do it so that we people with newbie questions and a need for examples can get out of your way and do it ourselves. You start by reading this: http://docs.python.org/documenting/index.html And this: http://www.python.org/dev/contributing/ And this: http://wiki.python.org/moin/WikiGuidelines The first link, which directly answers your question, is clearly listed on the doc contents page as Documenting Python. I'm uncertain how the docs could be made any _more_ helpful if people aren't prepared to put effort into reading them. We're a long way away from direct upload to the brain, unfortunately. If you're learning the language, you should also consider using more appropriate resources: http://mail.python.org/mailman/listinfo/tutor http://www.doughellmann.com/PyMOTW/ http://diveintopython.org/ The documentation cannot be all things to all people, and it most certainly can't be a guide to general programming, which is what often seems to be the issue with novice users. Python's a great language to learn how to program in, sure, but I would hate to see that become the focus of the docs. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regex
Robert Dailey wrote: Hey guys, I'm creating a python script that is going to try to search a text file for any text that matches my regular expression. The thing it is looking for is: FILEVERSION #,#,#,# The # symbol represents any number that can be any length 1 or greater. Example: FILEVERSION 1,45,10082,3 The regex should only match the exact above. So far here's what I have come up with: re.compile( r'FILEVERSION (?:[0-9]+\,){3}[0-9]+' ) This works, but I was hoping for something a bit cleaner. I'm having to create a special case portion of the regex for the last of the 4 numbers simply because it doesn't end with a comma like the first 3. Is there a better, more compact, way to write this regex? The character class \d is equivalent to [0-9], and ',' isn't a special character so it doesn't need to be escaped: re.compile(r'FILEVERSION (?:\d+,){3}\d+') -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regex
On Aug 7, 1:35 am, Robert Dailey rcdai...@gmail.com wrote: I'm creating a python script that is going to try to search a text file for any text that matches my regular expression. The thing it is looking for is: FILEVERSION 1,45,10082,3 Would it be easier to do it without regex? The following is untested but I would probably do it more like this: TOKEN = 'FILEVERSION ' for line in file: if line.startswith(TOKEN): version = line[len(TOKEN):] maj, min, rev, other = version.split(',') break # if there's only one occurance, otherwise do stuff here -- http://mail.python.org/mailman/listinfo/python-list
Character encoding the copyright symbol
Hello, I'm loading a file via open() in Python 3.1 and I'm getting the following error when I try to print the contents of the file that I obtained through a call to read(): UnicodeEncodeError: 'charmap' codec can't encode character '\xa9' in position 1650: character maps to undefined The file is defined as ASCII and the copyright symbol shows up just fine in Notepad++. However, Python will not print this symbol. How can I get this to work? And no, I won't replace it with (c). Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to comment on a Python PEP?
On 2009-08-06 03:42, Martin v. Löwis wrote: Is there a mechanism for submitting comments on a Python PEP? You post to python-dev or comp.lang.python, and you CC the author. And be sure to put the PEP number in the Subject: line. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regex
On Aug 6, 11:02 am, MRAB pyt...@mrabarnett.plus.com wrote: Robert Dailey wrote: Hey guys, I'm creating a python script that is going to try to search a text file for any text that matches my regular expression. The thing it is looking for is: FILEVERSION #,#,#,# The # symbol represents any number that can be any length 1 or greater. Example: FILEVERSION 1,45,10082,3 The regex should only match the exact above. So far here's what I have come up with: re.compile( r'FILEVERSION (?:[0-9]+\,){3}[0-9]+' ) This works, but I was hoping for something a bit cleaner. I'm having to create a special case portion of the regex for the last of the 4 numbers simply because it doesn't end with a comma like the first 3. Is there a better, more compact, way to write this regex? The character class \d is equivalent to [0-9], and ',' isn't a special character so it doesn't need to be escaped: re.compile(r'FILEVERSION (?:\d+,){3}\d+') But ',' is a special symbol It's used in this way: {0,3} This will match the previous regex 0-3 times. Are you sure commas need not be escaped? In any case, your suggestions help to clean it up a bit! -- http://mail.python.org/mailman/listinfo/python-list
Re: Web page data and urllib2.urlopen
On Aug 5, 4:30 pm, Massi massi_...@msn.com wrote: Hi everyone, I'm using the urllib2 library to get the html source code of web pages. In general it works great, but I'm having to do with a financial web site which does not provide the souce code I expect. As a matter of fact if you try: import urllib2 res = urllib2.urlopen(http://www.marketwatch.com/story/mondays- biggest-gaining-and-declining-stocks-2009-07-27) page = res.read() print page you will see that the printed code is very different from the one given, for example, by mozilla. Since I have really little knowledge in html I can't even understand if this is a python or html problem. Can anyone give me some help? Thanks in advance. Check if setting your user agent to Mozilla results in a different page: http://diveintopython.org/http_web_services/user_agent.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Python docs disappointing - group effort to hire writers?
alex23 wuwe...@gmail.com writes: No offence, but the last thing the official documentation needs is example code written by people learning how to code. Suggest changes, request clarifications, submit samples for review, sure, but direct modification by users? I've seen the PHP docs; thanks but no thanks. The PHP docs as I remember are sort of regular (non-publically editable) doc pages, each of which has a public discussion thread where people can post questions and answers about the topic of that doc page. I thought it worked really well. The main thing is that the good stuff from the comment section gets folded into the actual doc now and then. There is something similar with the PostgreSQL docs. There is also Real World Haskell (http://book.realworld.haskell.org) which has a lot of interspersed user comments. It would be cool if Python's doc site did something like it too. -- http://mail.python.org/mailman/listinfo/python-list
Re: unicode() vs. s.decode()
Thorsten Kampe wrote: * Michael Ströder (Wed, 05 Aug 2009 16:43:09 +0200) These both expressions are equivalent but which is faster or should be used for any reason? u = unicode(s,'utf-8') u = s.decode('utf-8') # looks nicer decode was added in Python 2.2 for the sake of symmetry to encode(). Yes, and I like the style. But... It's essentially the same as unicode() and I wouldn't be surprised if it is exactly the same. Did you try? I don't think any measurable speed increase will be noticeable between those two. Well, seems not to be true. Try yourself. I did (my console has UTF-8 as charset): Python 2.6 (r26:66714, Feb 3 2009, 20:52:03) [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 Type help, copyright, credits or license for more information. import timeit timeit.Timer('äöüÄÖÜß'.decode('utf-8')).timeit(100) 7.2721178531646729 timeit.Timer('äöüÄÖÜß'.decode('utf8')).timeit(100) 7.1302499771118164 timeit.Timer(unicode('äöüÄÖÜß','utf8')).timeit(100) 8.3726329803466797 timeit.Timer(unicode('äöüÄÖÜß','utf-8')).timeit(100) 1.8622009754180908 timeit.Timer(unicode('äöüÄÖÜß','utf8')).timeit(100) 8.651669979095459 Comparing again the two best combinations: timeit.Timer(unicode('äöüÄÖÜß','utf-8')).timeit(1000) 17.23644495010376 timeit.Timer('äöüÄÖÜß'.decode('utf8')).timeit(1000) 72.087096929550171 That is significant! So the winner is: unicode('äöüÄÖÜß','utf-8') Ciao, Michael. -- http://mail.python.org/mailman/listinfo/python-list
Re: Character encoding the copyright symbol
On Aug 6, 2009, at 12:14 PM, Robert Dailey wrote: Hello, I'm loading a file via open() in Python 3.1 and I'm getting the following error when I try to print the contents of the file that I obtained through a call to read(): UnicodeEncodeError: 'charmap' codec can't encode character '\xa9' in position 1650: character maps to undefined The file is defined as ASCII and the copyright symbol shows up just fine in Notepad++. However, Python will not print this symbol. How can I get this to work? And no, I won't replace it with (c). Thanks! If the file is defined as ASCII and it contains 0xa9, then the file was written incorrectly or you were told the wrong encoding. There is no such character in ASCII which runs from 0x00 - 0x7f. The copyright symbol == 0xa9 if the encoding is ISO-8859-1 or windows-1252, and since you're on Windows the latter is a likely bet. http://en.wikipedia.org/wiki/Ascii http://en.wikipedia.org/wiki/Iso-8859-1 http://en.wikipedia.org/wiki/Windows-1252 Bottom line is that your file is not in ASCII. Try specifying windows-1252 as the encoding. Without seeing your code I can't tell you where you need to specify the encoding, but the Python docs should help you out. HTH Philip -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regex
Robert Dailey wrote: On Aug 6, 11:02 am, MRAB pyt...@mrabarnett.plus.com wrote: Robert Dailey wrote: Hey guys, I'm creating a python script that is going to try to search a text file for any text that matches my regular expression. The thing it is looking for is: FILEVERSION #,#,#,# The # symbol represents any number that can be any length 1 or greater. Example: FILEVERSION 1,45,10082,3 The regex should only match the exact above. So far here's what I have come up with: re.compile( r'FILEVERSION (?:[0-9]+\,){3}[0-9]+' ) This works, but I was hoping for something a bit cleaner. I'm having to create a special case portion of the regex for the last of the 4 numbers simply because it doesn't end with a comma like the first 3. Is there a better, more compact, way to write this regex? The character class \d is equivalent to [0-9], and ',' isn't a special character so it doesn't need to be escaped: re.compile(r'FILEVERSION (?:\d+,){3}\d+') But ',' is a special symbol It's used in this way: {0,3} This will match the previous regex 0-3 times. Are you sure commas need not be escaped? In any case, your suggestions help to clean it up a bit! By 'special' I mean ones like '?', '*', '(', etc. ',' isn't special in that sense. In fact, the {...} quantifier is special only if it's syntactically correct, otherwise it's just a literal, eg a{, and a{} are just literals. -- http://mail.python.org/mailman/listinfo/python-list
Re: Character encoding the copyright symbol
Robert Dailey rcdai...@gmail.com wrote in message news:29ab0981-b95d-4435-91bd-a7a520419...@b15g2000yqd.googlegroups.com... UnicodeEncodeError: 'charmap' codec can't encode character '\xa9' in position 1650: character maps to undefined The file is defined as ASCII. That's the problem: ASCII is a seven bit code. What you have is actually ISO-8859-1 (or possibly Windows-1252). The different ISO-8859-n variants assign various characters to to '\xa9'. Rather than being Western-European centric and assuming ISO-8859-1 by default, Python throws an error when you stray outside of strict ASCII. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regex
On 06/08/09 08:35, Robert Dailey wrote: Hey guys, I'm creating a python script that is going to try to search a text file for any text that matches my regular expression. The thing it is looking for is: FILEVERSION #,#,#,# The # symbol represents any number that can be any length 1 or greater. Example: FILEVERSION 1,45,10082,3 The regex should only match the exact above. So far here's what I have come up with: re.compile( r'FILEVERSION (?:[0-9]+\,){3}[0-9]+' ) This works, but I was hoping for something a bit cleaner. I'm having to create a special case portion of the regex for the last of the 4 numbers simply because it doesn't end with a comma like the first 3. Is there a better, more compact, way to write this regex? -- http://mail.python.org/mailman/listinfo/python-list Since there cannot be more than one end of string you can try this expression: re.compile( r'FILEVERSION (?:[0-9]+(,|$)){4}' ) -- http://mail.python.org/mailman/listinfo/python-list
Re: Two Dimensional Array + ctypes
On Aug 5, 11:19 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Wed, 05 Aug 2009 20:12:09 -0300, Sparky samnspa...@gmail.com escribió: Hello! I am trying to call this method: long _stdcall AIBurst(long *idnum, [...] long timeout, float (*voltages)[4], long *stateIOout, long *overVoltage, long transferMode); I am having some problems with that float (*voltages)[4]. pointerArray = (ctypes.c_void_p * 4) voltages = pointerArray(ctypes.cast(ctypes.pointer ((ctypes.c_long * 4096)()), ctypes.c_void_p), ctypes.cast (ctypes.pointer((ctypes.c_long * 4096)()), ctypes.c_void_p), ctypes.cast(ctypes.pointer((ctypes.c_long * 4096)()), ctypes.c_void_p), ctypes.cast(ctypes.pointer((ctypes.c_long * 4096) Why c_long and not c_float? Anyway, this way looks much more clear to me (and doesn't require a cast): arr4096_type = ctypes.c_float * 4096 voltages_type = arr4096_type * 4 voltages = voltages_type() The program runs but the values that come back in the array are not right. Thay might be due to the long/float confusion. -- Gabriel Genellina Brilliant! Your code is much cleaner and the problem must have been float vs long. Thanks, Sam -- http://mail.python.org/mailman/listinfo/python-list
Re: Using easy_install, reduncant?
On Jul 27, 7:53 pm, David Lyon david.l...@preisshare.net wrote: On Mon, 27 Jul 2009 09:42:06 -0700 (PDT), ray ray.jos...@cdicorp.com wrote: I am working on a Trac installation. I am new to Python. To install packages, it is suggested to use setuptools. I have not understood the directions. I execute ez_install.py. Then I attempt to execute easy_install.py setuptools-0.6c9-py2.6.egg. There response that setuptools is already the active version in easy- install.pth. Then: Installing easy_install.exe script to C:\Python26\Scripts error: C: \Python26\Scripts\Easy_install.exe: Permission denied. I have compared the file entries before and after this attempt and there are no new files. Is there any problems here? What did I miss? Try using python package manager :http://sourceforge.net/projects/pythonpkgmgr/ You might find it a lot simpler. It will download and install setuptools for you if you are still having problems. David Is there any solution within the easy_install world? I'm trying to run a script (pinax) that calls it specifically so I'd have to do all sorts of hacking to use pythonpkgmgr. -- http://mail.python.org/mailman/listinfo/python-list
Re: Character encoding the copyright symbol
On Aug 6, 11:31 am, Richard Brodie r.bro...@rl.ac.uk wrote: Robert Dailey rcdai...@gmail.com wrote in message news:29ab0981-b95d-4435-91bd-a7a520419...@b15g2000yqd.googlegroups.com... UnicodeEncodeError: 'charmap' codec can't encode character '\xa9' in position 1650: character maps to undefined The file is defined as ASCII. That's the problem: ASCII is a seven bit code. What you have is actually ISO-8859-1 (or possibly Windows-1252). The different ISO-8859-n variants assign various characters to to '\xa9'. Rather than being Western-European centric and assuming ISO-8859-1 by default, Python throws an error when you stray outside of strict ASCII. Thanks for the help guys. Sorry I left out code, I wasn't sure at the time if it would be helpful. Below is my code: # def GetFileContentsAsString( file ): f = open( file, mode='r', encoding='cp1252' ) contents = f.read() f.close() return contents # def ReplaceVersion( file, version, regExps ): #match = regExps[0].search( 'FILEVERSION 1,45332,2100,32,' ) #print( match.group() ) text = GetFileContentsAsString( file ) print( text ) As you can see, I am trying to load the file with encoding 'cp1252' which, according to the python 3.1 docs, translates to windows-1252. I also tried 'latin_1', which translates to ISO-8859-1, but this did not work either. Am I doing something else wrong? -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regex
On Aug 6, 11:12 am, Roman atra...@gmail.com wrote: On 06/08/09 08:35, Robert Dailey wrote: Hey guys, I'm creating a python script that is going to try to search a text file for any text that matches my regular expression. The thing it is looking for is: FILEVERSION #,#,#,# The # symbol represents any number that can be any length 1 or greater. Example: FILEVERSION 1,45,10082,3 The regex should only match the exact above. So far here's what I have come up with: re.compile( r'FILEVERSION (?:[0-9]+\,){3}[0-9]+' ) This works, but I was hoping for something a bit cleaner. I'm having to create a special case portion of the regex for the last of the 4 numbers simply because it doesn't end with a comma like the first 3. Is there a better, more compact, way to write this regex? -- http://mail.python.org/mailman/listinfo/python-list Since there cannot be more than one end of string you can try this expression: re.compile( r'FILEVERSION (?:[0-9]+(,|$)){4}' ) I had thought of this but I can't use that either. I have to assume that someone was silly and put text at the end somewhere, perhaps a comment. Like so: FILEVERSION 1,2,3,4 // This is the file version It would be nice if there was a type of counter for regex. So you could say 'match only 1 [^,]' or something like that... -- http://mail.python.org/mailman/listinfo/python-list
Re: Character encoding the copyright symbol
On Thu, 2009-08-06 at 09:14 -0700, Robert Dailey wrote: Hello, I'm loading a file via open() in Python 3.1 and I'm getting the following error when I try to print the contents of the file that I obtained through a call to read(): UnicodeEncodeError: 'charmap' codec can't encode character '\xa9' in position 1650: character maps to undefined The file is defined as ASCII and the copyright symbol shows up just fine in Notepad++. However, Python will not print this symbol. How can I get this to work? And no, I won't replace it with (c). Thanks! It's not actually ASCII but Windows-1252 extended ASCII-like. So with that information you can do either of 2 things: You can open it in text mode and specify the encoding: fp = open(filename, 'r', encoding='windows-1252') s = fp.read() print(s) or you can open it in binary mode and decode it later: fp = open(filename, 'rb') b = fp.read() print(str(b, encoding='windows-1252')) Or you may be able to set the default encoding to windows-1252 but I don't know how to do that (in Windows). p.s. Next time it might be helpful to paste a code snippet else we have to make assumptions about what you are actually doing. -- http://mail.python.org/mailman/listinfo/python-list
Re: Character encoding the copyright symbol
On Aug 6, 2009, at 12:41 PM, Robert Dailey wrote: On Aug 6, 11:31 am, Richard Brodie r.bro...@rl.ac.uk wrote: Robert Dailey rcdai...@gmail.com wrote in message news:29ab0981-b95d-4435-91bd-a7a520419...@b15g2000yqd.googlegroups.com ... UnicodeEncodeError: 'charmap' codec can't encode character '\xa9' in position 1650: character maps to undefined The file is defined as ASCII. That's the problem: ASCII is a seven bit code. What you have is actually ISO-8859-1 (or possibly Windows-1252). The different ISO-8859-n variants assign various characters to to '\xa9'. Rather than being Western-European centric and assuming ISO-8859-1 by default, Python throws an error when you stray outside of strict ASCII. Thanks for the help guys. Sorry I left out code, I wasn't sure at the time if it would be helpful. Below is my code: # def GetFileContentsAsString( file ): f = open( file, mode='r', encoding='cp1252' ) contents = f.read() f.close() return contents # def ReplaceVersion( file, version, regExps ): #match = regExps[0].search( 'FILEVERSION 1,45332,2100,32,' ) #print( match.group() ) text = GetFileContentsAsString( file ) print( text ) As you can see, I am trying to load the file with encoding 'cp1252' which, according to the python 3.1 docs, translates to windows-1252. I also tried 'latin_1', which translates to ISO-8859-1, but this did not work either. Am I doing something else wrong? Are you getting the error when you read the file or when you print(text)? As a side note, you should probably use something other than file for the parameter name in GetFileContentsAsString() since file() is a Python function. -- http://mail.python.org/mailman/listinfo/python-list
Re: Character encoding the copyright symbol
Robert Dailey rcdai...@gmail.com wrote in message news:f64f9830-c416-41b1-a510-c1e486271...@g19g2000vbi.googlegroups.com... As you can see, I am trying to load the file with encoding 'cp1252' which, according to the python 3.1 docs, translates to windows-1252. I also tried 'latin_1', which translates to ISO-8859-1, but this did not work either. Am I doing something else wrong? Probably it's just the debugging print that has a problem, and if you opened an output file with an encoding specified it would be fine. When you get a UnicodeEncodingError, it's conversion _from_ Unicode that has failed. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Python to automate builds
On Aug 6, 3:57 am, David Cournapeau courn...@gmail.com wrote: On Thu, Aug 6, 2009 at 12:39 AM, Kostakosta.koe...@gmail.com wrote: Setenv.bat sets up the path and other environment variables build.exe needs to compile and link (and even binplace) its utilities. So building itself is not the issue. The problem is that if I call setenv.bat from Python and then build.exe, but the modifications to the path (and other environment settings) are not seen by Python, so the attempt to build without a specified path fails. It sounds like you do not propagate the environment when calling setenv.bat from python. There is an option to do so in subprocess.Popen init method, or you can define your own environment if you do not want to propagate the whole environment (but this is often difficult to avoid for build environment in my experience, expecially if you don't have access to the sources of the whole system to check which variables are necessary). David David, Thanks you. I looked up the docs on Popen (http://docs.python.org/ library/subprocess.html) where I read: On Windows: the Popen class uses CreateProcess() to execute the child program, which operates on strings. If args is a sequence, it will be converted to a string using the list2cmdline() method. Please note that not all MS Windows applications interpret the command line the same way: list2cmdline() is designed for applications using the same rules as the MS C runtime. My interpretation of the above (and your email) is that using Popen allows one to pass the Python environment to a child processs (in my case, setenv.bat). I need the reverse, to propagate from the child to the parent. Thanks, Kosta -- http://mail.python.org/mailman/listinfo/python-list
Re: Overlap in python
On Aug 4, 3:21 pm, Jay Bird jay.bird0...@gmail.com wrote: Hi everyone, I wanted to thank you all for your help and *excellent* discussion. I was able to utilize and embed the script by Grigor Lingl in the 6th post of this discussion to get my program to work very quickly (I had to do about 20 comparisons per data bin, with over 40K bins in total). I am involved in genomic analysis research and this problem comes up a lot and I was surprised to not have been able to find a clear way to solve it. I will also look through all the tips in this thread, I have a feeling they may come in handy for future use! Thank you again, Jay Hi Jay, I know this is a bit off-topic, but how does this pertain to genomic analysis? Are you counting the lengths of microsatellite repeats or something? -- http://mail.python.org/mailman/listinfo/python-list
Unexpected side-effects of assigning to sys.modules[__name__]
Given this module: #funny.py import sys print Before: print __name__ =, __name__ print sys.modules[__name__] =, sys.modules[__name__] sys.modules[__name__] = 123 print After: print __name__ =, __name__ print sys =, sys when I run it I get these results: [st...@sylar python]$ python2.6 funny.py Before: __name__ = __main__ sys.modules[__name__] = module '__main__' from 'funny.py' After: __name__ = None sys = None I'm completely perplexed by this behaviour. sys.modules() seems to be a regular dict, at least according to type(), and yet assigning to an item of it seems to have unexpected, and rather weird, side-effects. What am I missing? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regex
On Thu, 06 Aug 2009 08:35:57 -0700, Robert Dailey wrote: I'm creating a python script that is going to try to search a text file for any text that matches my regular expression. The thing it is looking for is: FILEVERSION #,#,#,# The # symbol represents any number that can be any length 1 or greater. Example: FILEVERSION 1,45,10082,3 The regex should only match the exact above. So far here's what I have come up with: re.compile( r'FILEVERSION (?:[0-9]+\,){3}[0-9]+' ) [0-9]+ allows any number of leading zeros, which is sometimes undesirable. Using: (0|[1-9][0-9]*) is more robust. -- http://mail.python.org/mailman/listinfo/python-list
Re: Unexpected side-effects of assigning to sys.modules[__name__]
Steven D'Aprano wrote: Given this module: #funny.py import sys print Before: print __name__ =, __name__ print sys.modules[__name__] =, sys.modules[__name__] sys.modules[__name__] = 123 print After: print __name__ =, __name__ print sys =, sys when I run it I get these results: [st...@sylar python]$ python2.6 funny.py Before: __name__ = __main__ sys.modules[__name__] = module '__main__' from 'funny.py' After: __name__ = None sys = None I'm completely perplexed by this behaviour. sys.modules() seems to be a regular dict, at least according to type(), and yet assigning to an item of it seems to have unexpected, and rather weird, side-effects. What am I missing? Maybe when you assign 123 to sys.modules[__name__], you've removed the last reference on module '__main__' from 'funny.py' and it is garbaged. You are then loosing all your initial namespace. try this one: #funny.py import sys print Before: print __name__ =, __name__ print sys.modules[__name__] =, sys.modules[__name__] foo = sys.modules[__name__] # backup ref for the garbage collector sys.modules[__name__] = 123 print After: print __name__ =, __name__ print sys =, sys Jean-Michel -- http://mail.python.org/mailman/listinfo/python-list
Re: unicode() vs. s.decode()
* Michael Ströder (Thu, 06 Aug 2009 18:26:09 +0200) Thorsten Kampe wrote: * Michael Ströder (Wed, 05 Aug 2009 16:43:09 +0200) I don't think any measurable speed increase will be noticeable between those two. Well, seems not to be true. Try yourself. I did (my console has UTF-8 as charset): Python 2.6 (r26:66714, Feb 3 2009, 20:52:03) [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 Type help, copyright, credits or license for more information. import timeit timeit.Timer('äöüÄÖÜß'.decode('utf-8')).timeit(100) 7.2721178531646729 timeit.Timer('äöüÄÖÜß'.decode('utf8')).timeit(100) 7.1302499771118164 timeit.Timer(unicode('äöüÄÖÜß','utf8')).timeit(100) 8.3726329803466797 timeit.Timer(unicode('äöüÄÖÜß','utf-8')).timeit(100) 1.8622009754180908 timeit.Timer(unicode('äöüÄÖÜß','utf8')).timeit(100) 8.651669979095459 Comparing again the two best combinations: timeit.Timer(unicode('äöüÄÖÜß','utf-8')).timeit(1000) 17.23644495010376 timeit.Timer('äöüÄÖÜß'.decode('utf8')).timeit(1000) 72.087096929550171 That is significant! So the winner is: unicode('äöüÄÖÜß','utf-8') Unless you are planning to write a loop that decodes äöüÄÖÜß one million times, these benchmarks are meaningless. Thorsten -- http://mail.python.org/mailman/listinfo/python-list
Python-URL! - weekly Python news and links (Aug 6)
QOTW: The economy rises and falls, money comes and goes, but a great conference has permanent good effects. Well, a lot more permanent than government fiscal policy, anyway. - Python Software Foundation Director bitter-in-victory-gracious-in-defeat-ly y'rs timbot Is python free of buffer overflow errors? http://groups.google.com/group/comp.lang.python/t/a31faac6feced289/ Lessons learned in implementation of a write-once dict: http://groups.google.com/group/comp.lang.python/t/bc8b91669257e246/ Methods, attributes, iterators, lambdas, and how Ruby handles them: http://groups.google.com/group/comp.lang.python/t/6e4fc61946513405/ Python 3 allows for custom types to be used as a class namespace not just dicts): http://groups.google.com/group/comp.lang.python/t/50caadd10d2cca16/ Could Python be used to write a device driver? http://groups.google.com/group/comp.lang.python/t/4efc28f9fe45b69e/ The various meanings of the underscore character '_' in identifiers: http://groups.google.com/group/comp.lang.python/t/e32d577ad3d5a208/ Generate a new object each time a name is imported: http://groups.google.com/group/comp.lang.python/t/b7112f74e2efa8bd/ heapq.nlargest takes a key argument - why not the other functions in the same module? http://groups.google.com/group/comp.lang.python/t/a5095d3f4b54f79b/ Immutable objects and how they could improve concurrency [old thread, still alive]: http://groups.google.com/group/comp.lang.python/t/cb0cf56c52321ccc/5c82cd09767ba85a?#5c82cd09767ba85a How to modify a variable in an outer (non global) scope: http://groups.google.com/group/comp.lang.python/t/e0e64250bd82825f/ Best way to add private directories to sys.path: http://groups.google.com/group/comp.lang.python/t/cb43cf90d72f6833/ Interval arithmetic: http://groups.google.com/group/comp.lang.python/t/71f050d8f5987244/ Ensure that no more than three instances of the same program are running at the same time: http://groups.google.com/group/comp.lang.python/t/af7ae6429c2bda1e/ Some people don't like the way Python documentation is managed/presented: http://groups.google.com/group/comp.lang.python/t/a52b22cd90b15ef8/ 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 gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes.
Re: Character encoding the copyright symbol
As a side note, you should probably use something other than file for the parameter name in GetFileContentsAsString() since file() is a Python function. Python 3.1.1a0 (py3k:74094, Jul 19 2009, 13:39:42) [GCC 4.3.3] on linux2 Type help, copyright, credits or license for more information. py file Traceback (most recent call last): File stdin, line 1, in module NameError: name 'file' is not defined Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: unicode() vs. s.decode()
On Thu, 06 Aug 2009 20:05:52 +0200, Thorsten Kampe wrote: That is significant! So the winner is: unicode('äöüÄÖÜß','utf-8') Unless you are planning to write a loop that decodes äöüÄÖÜß one million times, these benchmarks are meaningless. What if you're writing a loop which takes one million different lines of text and decodes them once each? setup = 'L = [abc*(n%100) for n in xrange(100)]' t1 = timeit.Timer('for line in L: line.decode(utf-8)', setup) t2 = timeit.Timer('for line in L: unicode(line, utf-8)', setup) t1.timeit(number=1) 5.6751680374145508 t2.timeit(number=1) 2.682251165771 Seems like a pretty meaningful difference to me. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Character encoding the copyright symbol
On Aug 6, 2009, at 3:14 PM, Martin v. Löwis wrote: As a side note, you should probably use something other than file for the parameter name in GetFileContentsAsString() since file() is a Python function. Python 3.1.1a0 (py3k:74094, Jul 19 2009, 13:39:42) [GCC 4.3.3] on linux2 Type help, copyright, credits or license for more information. py file Traceback (most recent call last): File stdin, line 1, in module NameError: name 'file' is not defined Whooops, didn't know about that change from 2.x to 3.x. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: pylucene installation problem on Ubuntu 9.04
On 6 Aug, 19:49, KK dioxide.softw...@gmail.com wrote: hi all, I've trying to install pylucene on my linux box from last 2 days but not able to do so. first i tried to install it using apt-get like this, kk-laptop$ sudo apt-get install pylucene and it did install python2.5, python2.5-minimal and pylucene. I must mention one thing that I already had python2.6 on my box as the default python i.e /usr/bin/python is linked to python2.6. Anyway s, now i started the python interpreter using python command from cli and then to make sure pylucene has been installed i tried to import the module and to my surprise it said module pylucene not found. I thought I should enter the python2.6 env and do the same , so i tried starting the python2.6 interpreter using python2.6 as the command and tried importing the same module and again it failed giving the same irritating message. As a final try i pulled the source code of pylucene and as per the comments given there in the README file, copied the mentioned files to site-packages directory of python2.6 and then tried importing the module and then got the same error message saying no module name pylucene is present. I'm sick of this error ! Can someone point me what is the issue? If it is due to multiple version of python running on box, can someone tell me which one to remove or someone tell me how to get the whole thing running? I'll very much thankful to you guys. Thanks, KK. If you installed using apt, have you a pylucene directory under /usr/ local/lib/python2.6/dist-packages/? Also, if you run python, and import sys; print sys.path whats it show? Jon. -- http://mail.python.org/mailman/listinfo/python-list
Re: pylucene installation problem on Ubuntu 9.04
On Thu, Aug 6, 2009 at 2:49 PM, KKdioxide.softw...@gmail.com wrote: kk-laptop$ sudo apt-get install pylucene and it did install python2.5, python2.5-minimal and pylucene. I must mention one thing that I already had python2.6 on my box as the default python i.e /usr/bin/python is linked to python2.6. Anyway s, now i started the python interpreter using python command from cli and then to make sure pylucene has been installed i tried to import the module and to my surprise it said module pylucene not found. I thought I should enter the python2.6 env and do the same , so i tried starting the python2.6 interpreter using python2.6 as the command and tried importing the same module and again it failed giving the same irritating message. Pylucene seems to have installed under Python 2.5. Python extensions are only installed for one version of python and extensions that use C may only work under one particular version. If you want to use that package, run python2.5 from the command line and try importing it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Character encoding the copyright symbol
On Thu, Aug 6, 2009 at 12:41 PM, Robert Daileyrcdai...@gmail.com wrote: On Aug 6, 11:31 am, Richard Brodie r.bro...@rl.ac.uk wrote: Robert Dailey rcdai...@gmail.com wrote in message news:29ab0981-b95d-4435-91bd-a7a520419...@b15g2000yqd.googlegroups.com... UnicodeEncodeError: 'charmap' codec can't encode character '\xa9' in position 1650: character maps to undefined The file is defined as ASCII. That's the problem: ASCII is a seven bit code. What you have is actually ISO-8859-1 (or possibly Windows-1252). The different ISO-8859-n variants assign various characters to to '\xa9'. Rather than being Western-European centric and assuming ISO-8859-1 by default, Python throws an error when you stray outside of strict ASCII. Thanks for the help guys. Sorry I left out code, I wasn't sure at the time if it would be helpful. Below is my code: # def GetFileContentsAsString( file ): f = open( file, mode='r', encoding='cp1252' ) contents = f.read() f.close() return contents # def ReplaceVersion( file, version, regExps ): #match = regExps[0].search( 'FILEVERSION 1,45332,2100,32,' ) #print( match.group() ) text = GetFileContentsAsString( file ) print( text ) As you can see, I am trying to load the file with encoding 'cp1252' which, according to the python 3.1 docs, translates to windows-1252. I also tried 'latin_1', which translates to ISO-8859-1, but this did not work either. Am I doing something else wrong? This is why we need code and full tracebacks. There's a good chance that your error is on the print(text) line. That's because sys.stdout is probably a byte stream without an encoding defined. When you try to print your unicode string, Python has to convert it to a stream of bytes. Python refuses to guess on the console encoding and just falls back to ascii, the conversion fails, and you get your error. Try using print( text.encode( 'cp1252' ) ) instead. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Python to automate builds
In article mailman.4290.1249482416.8015.python-l...@python.org, Hendrik van Rooyen hend...@microcorp.co.za wrote: Bit slow - but hey, nobody's perfect. YM pobody's nerfect HTH HAND -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ ...string iteration isn't about treating strings as sequences of strings, it's about treating strings as sequences of characters. The fact that characters are also strings is the reason we have problems, but characters are strings for other good reasons. --Aahz -- http://mail.python.org/mailman/listinfo/python-list
Re: How to write replace string for object which will be substituted? [regexp]
In article mailman.4260.1249424426.8015.python-l...@python.org, ryniek90 rynie...@gmail.com wrote: I started learning regexp, and some things goes well, but most of them still not. 1) 'Some people, when confronted with a problem, think I know, I'll use regular expressions. Now they have two problems.' --Jamie Zawinski, comp.emacs.xemacs, 8/1997 2) If you really want to learn regexes, get a copy of _Mastering Regular Expressions_ by Friedl (either 2nd or 3rd edition) -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ ...string iteration isn't about treating strings as sequences of strings, it's about treating strings as sequences of characters. The fact that characters are also strings is the reason we have problems, but characters are strings for other good reasons. --Aahz -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Python to automate builds
On Aug 6, 11:58 am, Piet van Oostrum p...@cs.uu.nl wrote: Kosta kosta.koe...@gmail.com (K) wrote: K My interpretation of the above (and your email) is that using Popen K allows one to pass the Python environment to a child processs (in my K case, setenv.bat). I need the reverse, to propagate from the child K to the parent. I don't think there is any modern OS that allows that. Unless you use your own protocol of course, like letting the child write the environment to its stdout and reading and interpreting it in the parent. -- Piet van Oostrum p...@cs.uu.nl URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org Piet, Yes you are correct. Thinking more about parent/child processes and what I am doing: opening a cmd window (its own process), starting up Python (a child process), and then attempting to run setenv.bat (a child process to Python), and yes I'm out of luck. -- http://mail.python.org/mailman/listinfo/python-list
Re: Character encoding the copyright symbol
Robert Dailey wrote: Hello, I'm loading a file via open() in Python 3.1 and I'm getting the following error when I try to print the contents of the file that I obtained through a call to read(): UnicodeEncodeError: 'charmap' codec can't encode character '\xa9' in position 1650: character maps to undefined The file is defined as ASCII and the copyright symbol shows up just fine in Notepad++. However, Python will not print this symbol. How can I get this to work? And no, I won't replace it with (c). Thanks! I see others have alerted you to changes needed in stdout, which is ASCII coded by default. But I wanted to comment on the (c) remark. If you're in the US, that's the wrong abbreviation for copyright. The only recognized abbreviation is (copr). DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Subclassing Python's dict
Are you referring to Python 3.0? Python 2.6 does not have collections.UserDict In Python2.6, it is in its own module. from UserDict import UserDict Raymond -- http://mail.python.org/mailman/listinfo/python-list
How to write replace string for object which will be substituted? [regexp]
2) If you really want to learn regexes, get a copy of _Mastering Regular Expressions_ by Friedl (either 2nd or 3rd edition) I made preview of that book, but some pages are disabled from preview. Has that book topics about Python regexp's? If so, i must buy it. -- http://mail.python.org/mailman/listinfo/python-list
Re: os.walk()
On Tue, Aug 4, 2009 at 10:48 PM, Chris Rebert c...@rebertia.com wrote: On Tue, Aug 4, 2009 at 7:06 PM, Michael Savaresegeomajo...@gmail.com wrote: Greetings Python newbie here, and thanks to all who have helped me previously. Is there a way of grabbing file attributes while traversing with os.walk()? It would be advantageous to have date modified and file size along with the file name. If anyone can point me in the right direction, I'd appreciate it. Feed the path to os.stat(), and then use the `stat` module on the result: http://docs.python.org/library/os.html#os.stat http://docs.python.org/library/stat.html#module-stat 2009/8/5 Michael Savarese geomajo...@gmail.com: Chris, thanks for the info. I'm a bit stuck here. am i close? Yes, you just need to plug some more bricks together (as it were). import os, sys import os.path for root, dirs, files in os.walk('c:/Temp'): for name in files: statinfo=os.stat(name) #see http://docs.python.org/library/os.path.html#os.path.join filepath = os.path.join(root, name) statinfo = os.stat(filepath) print root,dirs,name,statinfo.st_size ; it gets stuck here, i guess it needs the full path. is this where i use the join function to bring root, dirs, and filename together? I kinda suck at that too, can you point me in the right direction? also: statinfo.st_mtime 1247778166.6563497 can i have a hint on how to convert this? That is the time represented in seconds since the (UNIX) epoch. Use the functions in the `time` module to convert it to something more palatable: http://docs.python.org/library/time.html Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How to write replace string for object which will be substituted? [regexp]
On Thu, Aug 6, 2009 at 2:03 PM, Ryniek90rynie...@gmail.com wrote: 2) If you really want to learn regexes, get a copy of _Mastering Regular Expressions_ by Friedl (either 2nd or 3rd edition) I made preview of that book, but some pages are disabled from preview. Has that book topics about Python regexp's? If so, i must buy it. Yes, Python is among the language APIs covered. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Subclassing Python's dict
Xavier Ho wrote: You should subclass collections.UserDict, and not the default dict class. Refer to the collections module. Xavier, why do you think that is the correct approach? The docs say The need for this class has been largely supplanted by the ability to subclass directly from dict (a feature that became available starting with Python version 2.2). UserDict can be a good choice because the pure python source makes it clear exactly what needs to be overridden (you can see which methods are implemented in terms of lower level methods and which ones access the underlying dict directly. Another choice is to use DictMixin or MutableMapping and fill-in just the required abstract methods. This approach is simple and flexible. It allows you to wrap a mapping interface around many different classes (a dbm for example). The disadvantage is that it can be slow. Subclassing a dict is typically done when the new class has to be substitutable for real dicts (perhaps an API enforces a check for instance(x, dict) or somesuch). As the OP found out, the dict methods all access the underlying structure directly, so you will need to override *all* methods that need to have a new behavior. The remaining methods are inherited and run at C speed, so performance may dictate this approach. So, there you have three ways to do it. In Py3.1, we used the latter approach for collections.Counter() -- that gives a high speed on the inherited methods. For collections.OrderedDict, a hybrid approach was used (subclassing from both dict and MutableMapping). Most of the work is done by MutableMapping and the dict is inherited so that the OrderedDict objects would be substitutable anywhere regular dicts are expected. And IIRC, there are still some cases of UserDict being used in the python source (situations where subclassing from dict wouldn't work as well). Raymond -- http://mail.python.org/mailman/listinfo/python-list
Re: Seeding the rand() Generator
Hi Fred, I just saw your SQL Statement An example would be: SELECT first, second, third, fourth, fifth, sixth from sometable order by rand() limit 1 and I feel me constrained to give you an advice. Don't use this SQL statement to pick up a random row, your user and maybe DBA would much appreciate it. You are certainly asking why. Lets have a brief look what you are asking your mysql DB: Fetch all rows from 'sometable', but only with attribute 'first, second,...' sort them all starting at 'random row' and afterward through anything away you did before, but the first line If you have a table with 10 rows you would fetch and sort up to 10 rows, pick up one row and discard up to 9 rows. That sounds not very clever, right? So please take a look at this site to get a better alternate way for that approach: http://jan.kneschke.de/projects/mysql/order-by-rand/ if you want to know more please check this article too: http://jan.kneschke.de/2007/2/22/analyzing-complex-queries regards, Nils -- http://mail.python.org/mailman/listinfo/python-list
Re: os.path.exists() and Samba shares
On Jul 31, 10:56 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Fri, 31 Jul 2009 13:33:45 -0300, BDZ bdezo...@wisc.edu escribió: On Jul 30, 4:41 pm, Loïc Domaigné loic.domai...@googlemail.com wrote: Hello. I have written a Python 3.1 script running on Windows that uses os.path.exists() to connect to network shares. If the various network shares require different user account and password combos than the account the script is running under the routine returns false. I need something like os.samba.path.exists(username,password,path). Does anyone have a suggestion on how I can accomplish what I need to do in Python? Could the Python Samba module PySamba be interesting for you?http://sourceforge.net/projects/pysamba/ Unfortunately, although it has the calls I'd want, pysamba appears to be *nix only. I need something that will work under Windows. Is there a set of Python Windows functions (official or contributed) that might do what I need? (I'm new to Python) SAMBA is a Linux implementation of the SMB protocol, natively supported on Windows. You may use the pywin32 package (available on sourceforge.net) to call the WNetAddConnection2 Windows function:http://msdn.microsoft.com/en-us/library/aa385413(VS.85).aspx -- Gabriel Genellina The WNetAddConnection2 function under pywin32 seems to work. I am able to make connections to various SMB network resources hosted by Windows, Mac, and Linux boxes. It has the annoying side effect of opening a connection. There is a Win32 function called NetShareCheck. It sounds perfect. It just checks that the share exists (no connection left open) and does not require username or password. Unfortunately it fails for Mac and Linux SMB resources. Just FYI. I understand Samba and Windows SMB are not the same thing. What I was hoping for when I investigated pySamba was to find a python module/ extension that supported a simple SMB interface and would run from any host platform. -- http://mail.python.org/mailman/listinfo/python-list
XML flaw
Hi all, I've just read this article, which mentions Python: XML flaw threatens millions of apps with DoS attacks http://infoworld.com/print/86340 Something to worry about? -- http://mail.python.org/mailman/listinfo/python-list
Re: Unexpected side-effects of assigning to sys.modules[__name__]
On Thu, 06 Aug 2009 20:01:42 +0200, Jean-Michel Pichavant wrote: I'm completely perplexed by this behaviour. sys.modules() seems to be a regular dict, at least according to type(), and yet assigning to an item of it seems to have unexpected, and rather weird, side-effects. What am I missing? Maybe when you assign 123 to sys.modules[__name__], you've removed the last reference on module '__main__' from 'funny.py' and it is garbaged. You are then loosing all your initial namespace. By Jove, I think you've got it! How obvious in hindsight. Thank you. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: Web page data and urllib2.urlopen
Piet van Oostrum wrote: snip DA If Mozilla had seen a page with this line in an appropriate place, it'd DA immediately begin loading the other page, at someotherurl But there's no DA such line. DA Next, I looked for javascript. The Mozilla page contains lots of DA javascript, but there's none in the raw page. So I can't explain Mozilla's DA differences that way. DA I did notice the link to /m/Content/mobile2.css, but I don' t know any way DA a CSS file could cause the content to change, just the display. DA All I can guess is that it has something to do with browser type or DA cookies. And that would make lots of sense if this was a cgi page. But DA the URL doesn't look like that, as it doesn't end in pl, py, asp, or any of DA another dozen special suffixes. DA Any hints, anybody??? If you look into the HTML that Firefox gets, there is a lot of javascript in it. But the raw page didn't have any javascript. So what about that original raw page triggered additional stuff to be loaded? Is it user agent, as someone else brought out? And is there somewhere I can read more about that aspect of things? I've mostly built very static html pages, where the server yields the same page to everybody. And some form stuff, where the user clicks on a 'submit button to trigger a script that's not shown on the URL line. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regex
Nobody wrote: On Thu, 06 Aug 2009 08:35:57 -0700, Robert Dailey wrote: I'm creating a python script that is going to try to search a text file for any text that matches my regular expression. The thing it is looking for is: FILEVERSION #,#,#,# The # symbol represents any number that can be any length 1 or greater. Example: FILEVERSION 1,45,10082,3 The regex should only match the exact above. So far here's what I have come up with: re.compile( r'FILEVERSION (?:[0-9]+\,){3}[0-9]+' ) [0-9]+ allows any number of leading zeros, which is sometimes undesirable. Using: (0|[1-9][0-9]*) is more robust. You make a good point about possibly being undesirable, but I question the assertion that your solution is /more robust/. If the OP wants/needs to match numbers even with leading zeroes your /more robust/ version fails. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: XML flaw
On Thu, Aug 6, 2009 at 3:05 PM, MRABpyt...@mrabarnett.plus.com wrote: Hi all, I've just read this article, which mentions Python: XML flaw threatens millions of apps with DoS attacks http://infoworld.com/print/86340 Something to worry about? More detailed article: http://blogs.zdnet.com/open-source/?p=4609 Quote: If you own any of the following libraries you need to be alert and ready to patch: * Python libexpat AKA xml.parsers.expat AKA pyexpat The good news: [a patch] is in process for Python. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: XML flaw
MRAB wrote: Hi all, I've just read this article, which mentions Python: XML flaw threatens millions of apps with DoS attacks http://infoworld.com/print/86340 Something to worry about? No. Discussing letting Tom, Dick and Harriet loose on the Python documentaion is far more important than trivial issues like Denial of Service atacks via XML. Sorry, just couldn't resist. -- Kindest regards. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Setuptools - help!
Chaps, any ideas, I'm floundering - I don't quite get it. I have the following files, setup.py and main.py in a directory pphoto: # more setup.py from setuptools import setup, find_packages setup( name = Pphoto, version = 0.1, packages = find_packages(), # other arguments here... entry_points = {'console_scripts': ['foo = pphoto.main:HelloWorld',]} ) bash-3.1# more main.py def HelloWorld(): print Hello World! print Odd world From various websites that should produce a script foo that runs HelloWorld. It does produce a script that simply crashes. bash-3.1# foo Traceback (most recent call last): File /usr/bin/foo, line 8, in module load_entry_point('Pphoto==0.1', 'console_scripts', 'foo')() File build/bdist.linux-i686/egg/pkg_resources.py, line 277, in load_entry_point File build/bdist.linux-i686/egg/pkg_resources.py, line 2098, in load_entry_point File build/bdist.linux-i686/egg/pkg_resources.py, line 1831, in load ImportError: No module named pphoto.main bash-3.1# Note, doing this as root as it seems not to do anything usefull at all if I run python setup develop as a user. Any ideas? I must be missing something fundamental? Pete -- http://www.petezilla.co.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Setuptools - help!
On 2009-08-06 18:04, Peter Chant wrote: Chaps, any ideas, I'm floundering - I don't quite get it. I have the following files, setup.py and main.py in a directory pphoto: # more setup.py from setuptools import setup, find_packages setup( name = Pphoto, version = 0.1, packages = find_packages(), # other arguments here... entry_points = {'console_scripts': ['foo = pphoto.main:HelloWorld',]} ) bash-3.1# more main.py def HelloWorld(): print Hello World! print Odd world From various websites that should produce a script foo that runs HelloWorld. It does produce a script that simply crashes. bash-3.1# foo Traceback (most recent call last): File /usr/bin/foo, line 8, inmodule load_entry_point('Pphoto==0.1', 'console_scripts', 'foo')() File build/bdist.linux-i686/egg/pkg_resources.py, line 277, in load_entry_point File build/bdist.linux-i686/egg/pkg_resources.py, line 2098, in load_entry_point File build/bdist.linux-i686/egg/pkg_resources.py, line 1831, in load ImportError: No module named pphoto.main bash-3.1# Note, doing this as root as it seems not to do anything usefull at all if I run python setup develop as a user. Any ideas? I must be missing something fundamental? You need to put main.py into the pphoto package. $ mkdir pphoto/ $ mv main.py pphoto/ $ touch pphoto/__init__.py -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Python3: Using sorted(key=...)
Hello list, I'm having trouble with a incredibly simple sort of a list containing ints and tuples: def myorder(x): if type(x) == int: return x else: return x[0] odata = sorted([ (a, b) for (a, b) in data[description].items() ], key=myorder) still says: Traceback (most recent call last): File ./genproto.py, line 81, in module odata = sorted([ (a, b) for (a, b) in data[description].items() ], key=myorder) TypeError: unorderable types: tuple() int() Why is that? Am I missing something very obvious? Kind regards, Johannes -- Du bist einfach nur lächerlich! Mit solchen albernen und hohlen Sätzen kannst du mir nicht imprägnieren. -- Hobbycholeriker Jens Fittig aka Wolfgang Gerber in de.sci.electronics 4a6f44d0$0$12481$9b622...@news.freenet.de -- http://mail.python.org/mailman/listinfo/python-list
Re: heapq key arguments
On Aug 3, 1:36 pm, Raymond Hettinger pyt...@rcn.com wrote: [Joshua Bronson]: According tohttp://docs.python.org/library/heapq.html, Python 2.5 added an optional key argument to heapq.nsmallest and heapq.nlargest. I could never understand why they didn't also add a key argument to the other relevant functions (heapify, heappush, etc). The problem is that heapq acts on regular lists, so it does not have exclusive access to the structure. So, there is no reliable way for it to maintain a separate list of keys. Since the keys can't be saved in the structure (without possibly breaking other code), the fine grained heapq functions (like heappop and heappush) would need to call key functions every time they are invoked. This is at odds with the implicit guarantee of the key function that it will be called no more than once per key. The overall problem is one of granularity. A key function should be applied once in an initial pass, not on every call to a push/pop function. The everyday solution that most people use is to operate on a list of (key, record) tuples and let tuple comparison do the work for you. Another solution is to build a Heap class that does have exclusive access to the structure, but the API sugar often isn't worth the slightly weaker performance. One other thought. Heaps are a lazy evaluation structure, so their fined-grained mutation functions only work well with just a single ordering function, so there is not need to have (and every reason to avoid) changing key functions in mid-stream. IOW, the key function needs to be constant across all accesses. Contrast this with other uses of key functions where it makes perfect sense to run minage=min(data, key=attrgetter('age')) and then running minsal=min(data, key=attrgetter('salary')). The flexibility to change key functions just doesn't make sense in the context of the fine-grained heap functions. Accordingly, this is why I put key functions in nlargest() and nsmallest() but not in heappush() and friends. The former can guarantee no more than one key function call per entry and they evaluate immediately instead of lazily. Raymond I see, that makes sense. Thanks for the great explanation. Josh -- http://mail.python.org/mailman/listinfo/python-list
Re: Help making this script better
En Thu, 06 Aug 2009 11:50:07 -0300, jakecjacobson jakecjacob...@gmail.com escribió: After much Google searching and trial error, I was able to write a Python script that posts XML files to a REST API using HTTPS and passing PEM cert key file. It seems to be working but would like some pointers on how to handle errors. I am using Python 2.4, I don't have the capability to upgrade even though I would like to. I am very new to Python so help will be greatly appreciated and I hope others can use this script. Just a few remarks, mostly on style rather than functionality: #!/usr/bin/python # # catalog_feeder.py # # This sciript will process a directory of XML files and push them to the Enterprise Catalog. # You configure this script by using a configuration file that describes the required variables. # The path to this file is either passed into the script as a command line argument or hard coded # in the script. The script will terminate with an error if it can't process the XML file. # Note that Python has docstrings - the __doc__ attribute attached to every module, class and function. The very first string in the module/function/class becomes its docstring. The interactive help system -and other tools like pydoc- can inspect and show such info. The above comment could serve perfectly as this module's docstring - just remove all the #'s and enclose the whole text in triple quotes (required as it spawns many lines). By example, in that case you could print the text in your usage() function like this: print __doc__ try: # Process the XML conf file xmldoc = minidom.parse(c) catalog_host = readConfFile(xmldoc, 'catalog_host') catalog_port = int(readConfFile(xmldoc, 'catalog_port')) catalog_path = readConfFile(xmldoc, 'catalog_path') collection_name = readConfFile(xmldoc, 'collection_name') cert_file = readConfFile(xmldoc, 'cert_file') key_file = readConfFile(xmldoc, 'key_file') log_file = readConfFile(xmldoc, 'log_file') input_dir = readConfFile(xmldoc, 'input_dir') archive_dir = readConfFile(xmldoc, 'archive_dir') hold_dir = readConfFile(xmldoc, 'hold_dir') except Exception, inst: # I had an error so report it and exit script print Unexpected error opening %s: %s % (c, inst) sys.exit(1) Ok, an unexpected error: but *which* one? doing exactly *what*? You're hiding important information (the error type, the full traceback, the source line that raised the error...) that's very valuable when something goes wrong and you have to determine what happened. In this case, you're adding a bit of information: the name of the file being processed. That's good. But at the same time, hiding all the other info, and that's not so good. What about this: except Exception: print sys.stderr, Unexpected error opening %s % c raise The final raise will propagate the exception; by default, Python will print the exception type, the exception value, the full traceback including source lines, and exit the script with a status code of 1. The same effect that you intended, but more complete. In other cases, where you don't have anything to add to the default exception handling, the best thing to do is: nothing. That is, don't catch an exception unless you have something good to do with it. (Exceptions aren't Pokémon: you don't have to catch 'em all!) # Log Starting logOut = verifyLogging(log_file) if logOut: log(logOut, Processing Started ...) I would move the decision into the log function (that is, just write log(something) and make the log function decide whether to write to file or not). For your next script, look at the logging module: http://docs.python.org/library/logging.html # Get an arry of files from the input_dir def getFiles2Post(d): return (os.listdir(d)) Note that return isn't a function but a statement. You don't need the outer (). Also, using a docstring instead of a comment: def getFiles2Post(input_dir): Return the list of files in input_dir to process return os.listdir(input_dir) # Read out the conf file and set the needed global variable def readConfFile(xmldoc, tag): return (xmldoc.getElementsByTagName(tag)[0].firstChild.data) Same as above. Which needed global variable? def cleanup(logOut): [...] sys.exit(0) Exiting the script from everywhere makes it harder to reuse some of its functions later. Just return the desired status code to the caller, which in turn will
Re: Subclassing Python's dict
En Thu, 06 Aug 2009 05:26:22 -0300, Xavier Ho cont...@xavierho.com escribió: On Thu, Aug 6, 2009 at 1:19 PM, alex23 wuwe...@gmail.com wrote: Xavier Ho wrote: You should subclass collections.UserDict, and not the default dict class. Xavier, why do you think that is the correct approach? I'll be honest first and say that I do not completely understand how dict is implemented in the underlying C structure. But as Bruno had already mentioned, dict has a slightly different behaviour then we'd expect. For example, the __getitem__() function isn't actually used by the interpreter (which, you know, *can* be a problem.) Thinks have evolved... Before Python 2.2, builtin types were not subclassable. You could not inherit from dict. In order to write another mapping class, you had to write the complete interface - or inherit from UserDict, that was a concrete class implementing the mapping protocol. Later, DictMixin was added (in 2.3) and it made easier to write other mapping classes: one had to write the most basic methods (__getitem__ / __setitem__ / __delitem__ / keys) and the DictMixin provided the remaining functionality (e.g. values() is built from keys() plus __getitem__). Later releases allowed an even more modular approach, and until 2.5 DictMixin was the recommended approach. Then came 3.0/2.6 and PEP3119 defining a rich hierarchy of abstract base classes; a normal dictionary implements the MutableMapping ABC and this is the preferred approach now (the MutableMapping implementation is very similar to the original DictMixin, but builds on the other base classes like Sized, Iterable...) I didn't realise they took UserDict out in later versions (2.6, for example), and put it back in Python 3.0. Does anyone know why? UserDict still exists on both releases (collections.UserDict on 3.x), but it's not the preferred approach to implement a new mapping class anymore. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regex
On Aug 7, 7:23 am, Ethan Furman et...@stoneleaf.us wrote: Nobody wrote: On Thu, 06 Aug 2009 08:35:57 -0700, Robert Dailey wrote: I'm creating a python script that is going to try to search a text file for any text that matches my regular expression. The thing it is looking for is: FILEVERSION #,#,#,# The # symbol represents any number that can be any length 1 or greater. Example: FILEVERSION 1,45,10082,3 The regex should only match the exact above. So far here's what I have come up with: re.compile( r'FILEVERSION (?:[0-9]+\,){3}[0-9]+' ) [0-9]+ allows any number of leading zeros, which is sometimes undesirable. Using: (0|[1-9][0-9]*) is more robust. You make a good point about possibly being undesirable, but I question the assertion that your solution is /more robust/. If the OP wants/needs to match numbers even with leading zeroes your /more robust/ version fails. I'd go further: the OP would probably be better off matching anything that looked vaguely like an attempt to produce what he wanted e.g. rFILEVERSION\s*[0-9,]{3,} and then taking appropriate action based on whether that matched a strictly correct regex. -- http://mail.python.org/mailman/listinfo/python-list
Re: unicode() vs. s.decode()
Thorsten Kampe wrote: * Michael Ströder (Thu, 06 Aug 2009 18:26:09 +0200) timeit.Timer(unicode('äöüÄÖÜß','utf-8')).timeit(1000) 17.23644495010376 timeit.Timer('äöüÄÖÜß'.decode('utf8')).timeit(1000) 72.087096929550171 That is significant! So the winner is: unicode('äöüÄÖÜß','utf-8') Unless you are planning to write a loop that decodes äöüÄÖÜß one million times, these benchmarks are meaningless. Well, I can tell you I would not have posted this here and checked it if it would be meaningless for me. You don't have to read and answer this thread if it's meaningless to you. Ciao, Michael. -- http://mail.python.org/mailman/listinfo/python-list